array_pop.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. --TEST--
  2. Test array_pop() function
  3. --FILE--
  4. <?php
  5. $empty_array = array();
  6. $number = 5;
  7. $str = "abc";
  8. /* Various combinations of arrays to be used for the test */
  9. $mixed_array = array(
  10. array(),
  11. array( 1,2,3,4,5,6,7,8,9 ),
  12. array( "One", "_Two", "Three", "Four", "Five" ),
  13. array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ),
  14. array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ),
  15. array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ),
  16. array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ),
  17. array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF",
  18. "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ),
  19. array( 12, "name", 'age', '45' ),
  20. array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ),
  21. array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6,
  22. 5 => 57, "5.4" => 554, "5.7" => 557 )
  23. );
  24. /* Loop to test normal functionality with different arrays inputs */
  25. echo "\n*** Normal testing with various array inputs ***\n";
  26. $counter = 1;
  27. foreach( $mixed_array as $sub_array )
  28. {
  29. echo "\n-- Input Array for Iteration $counter is --\n";
  30. var_dump( $sub_array );
  31. echo "\nOutput after Pop is :\n";
  32. var_dump( array_pop($sub_array) );
  33. $counter++;
  34. }
  35. echo"\nDone";
  36. ?>
  37. --EXPECT--
  38. *** Normal testing with various array inputs ***
  39. -- Input Array for Iteration 1 is --
  40. array(0) {
  41. }
  42. Output after Pop is :
  43. NULL
  44. -- Input Array for Iteration 2 is --
  45. array(9) {
  46. [0]=>
  47. int(1)
  48. [1]=>
  49. int(2)
  50. [2]=>
  51. int(3)
  52. [3]=>
  53. int(4)
  54. [4]=>
  55. int(5)
  56. [5]=>
  57. int(6)
  58. [6]=>
  59. int(7)
  60. [7]=>
  61. int(8)
  62. [8]=>
  63. int(9)
  64. }
  65. Output after Pop is :
  66. int(9)
  67. -- Input Array for Iteration 3 is --
  68. array(5) {
  69. [0]=>
  70. string(3) "One"
  71. [1]=>
  72. string(4) "_Two"
  73. [2]=>
  74. string(5) "Three"
  75. [3]=>
  76. string(4) "Four"
  77. [4]=>
  78. string(4) "Five"
  79. }
  80. Output after Pop is :
  81. string(4) "Five"
  82. -- Input Array for Iteration 4 is --
  83. array(8) {
  84. [0]=>
  85. int(6)
  86. [1]=>
  87. string(3) "six"
  88. [2]=>
  89. int(7)
  90. [3]=>
  91. string(5) "seven"
  92. [4]=>
  93. int(8)
  94. [5]=>
  95. string(5) "eight"
  96. [6]=>
  97. int(9)
  98. [7]=>
  99. string(4) "nine"
  100. }
  101. Output after Pop is :
  102. string(4) "nine"
  103. -- Input Array for Iteration 5 is --
  104. array(5) {
  105. ["a"]=>
  106. string(3) "aaa"
  107. ["A"]=>
  108. string(3) "AAA"
  109. ["c"]=>
  110. string(3) "ccc"
  111. ["d"]=>
  112. string(3) "ddd"
  113. ["e"]=>
  114. string(3) "eee"
  115. }
  116. Output after Pop is :
  117. string(3) "eee"
  118. -- Input Array for Iteration 6 is --
  119. array(5) {
  120. [1]=>
  121. string(3) "one"
  122. [2]=>
  123. string(3) "two"
  124. [3]=>
  125. string(5) "three"
  126. [4]=>
  127. string(4) "four"
  128. [5]=>
  129. string(4) "five"
  130. }
  131. Output after Pop is :
  132. string(4) "five"
  133. -- Input Array for Iteration 7 is --
  134. array(5) {
  135. [1]=>
  136. string(3) "one"
  137. [2]=>
  138. string(3) "two"
  139. [3]=>
  140. int(7)
  141. [4]=>
  142. string(4) "four"
  143. [5]=>
  144. string(4) "five"
  145. }
  146. Output after Pop is :
  147. string(4) "five"
  148. -- Input Array for Iteration 8 is --
  149. array(12) {
  150. ["f"]=>
  151. string(3) "fff"
  152. [1]=>
  153. string(3) "one"
  154. [4]=>
  155. int(6)
  156. [""]=>
  157. int(3)
  158. [2]=>
  159. string(5) "float"
  160. ["F"]=>
  161. string(3) "FFF"
  162. ["blank"]=>
  163. string(0) ""
  164. [3]=>
  165. float(3.7)
  166. [5]=>
  167. string(4) "Five"
  168. [6]=>
  169. float(8.6)
  170. ["4name"]=>
  171. string(5) "jonny"
  172. ["a"]=>
  173. NULL
  174. }
  175. Output after Pop is :
  176. NULL
  177. -- Input Array for Iteration 9 is --
  178. array(4) {
  179. [0]=>
  180. int(12)
  181. [1]=>
  182. string(4) "name"
  183. [2]=>
  184. string(3) "age"
  185. [3]=>
  186. string(2) "45"
  187. }
  188. Output after Pop is :
  189. string(2) "45"
  190. -- Input Array for Iteration 10 is --
  191. array(3) {
  192. [0]=>
  193. array(3) {
  194. [0]=>
  195. string(3) "oNe"
  196. [1]=>
  197. string(3) "tWo"
  198. [2]=>
  199. int(4)
  200. }
  201. [1]=>
  202. array(5) {
  203. [0]=>
  204. int(10)
  205. [1]=>
  206. int(20)
  207. [2]=>
  208. int(30)
  209. [3]=>
  210. int(40)
  211. [4]=>
  212. int(50)
  213. }
  214. [2]=>
  215. array(0) {
  216. }
  217. }
  218. Output after Pop is :
  219. array(0) {
  220. }
  221. -- Input Array for Iteration 11 is --
  222. array(10) {
  223. ["one"]=>
  224. int(2)
  225. ["three"]=>
  226. int(3)
  227. [0]=>
  228. int(3)
  229. [1]=>
  230. int(4)
  231. [3]=>
  232. int(33)
  233. [4]=>
  234. int(44)
  235. [5]=>
  236. int(57)
  237. [6]=>
  238. int(6)
  239. ["5.4"]=>
  240. int(554)
  241. ["5.7"]=>
  242. int(557)
  243. }
  244. Output after Pop is :
  245. int(557)
  246. Done