array_pop.phpt 3.5 KB

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