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