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