1--TEST--
2Test array_unshift() function : usage variations - different array values for 'array' argument
3--FILE--
4<?php
5/*
6 * Testing the behavior of array_unshift() by passing different types of arrays
7 * to $array argument to which the $var arguments will be prepended
8*/
9
10echo "*** Testing array_unshift() : different arrays for \$array argument ***\n";
11
12// initialize $var argument
13$var = 10;
14
15// different arrays to be passed to $array argument
16$arrays = array (
17/*1*/  array(1, 2), // array with default keys and numeric values
18       array(1.1, 2.2), // array with default keys & float values
19       array( array(2), array(1)), // sub arrays
20       array(false,true), // array with default keys and boolean values
21       array(), // empty array
22       array(NULL), // array with NULL
23       array("a","aaaa","b","bbbb","c","ccccc"),
24
25       // associative arrays
26/*8*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
27       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
28       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
29       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
30       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
31
32       // associative array, containing null/empty/boolean values as key/value
33/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
34       array(true => "true", false => "false", "false" => false, "true" => true),
35       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
36       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
37       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
38
39       // array with repetitive keys
40/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
41);
42
43// loop through the various elements of $arrays to test array_unshift()
44$iterator = 1;
45foreach($arrays as $array) {
46  echo "-- Iteration $iterator --\n";
47
48  /* with default argument */
49  // returns element count in the resulting array after arguments are pushed to
50  // beginning of the given array
51  $temp_array = $array;
52  var_dump( array_unshift($temp_array, $var) );
53
54  // dump the resulting array
55  var_dump($temp_array);
56
57  /* with optional arguments */
58  // returns element count in the resulting array after arguments are pushed to
59  // beginning of the given array
60  $temp_array = $array;
61  var_dump( array_unshift($temp_array, $var, "hello", 'world') );
62
63  // dump the resulting array
64  var_dump($temp_array);
65  $iterator++;
66}
67
68echo "Done";
69?>
70--EXPECT--
71*** Testing array_unshift() : different arrays for $array argument ***
72-- Iteration 1 --
73int(3)
74array(3) {
75  [0]=>
76  int(10)
77  [1]=>
78  int(1)
79  [2]=>
80  int(2)
81}
82int(5)
83array(5) {
84  [0]=>
85  int(10)
86  [1]=>
87  string(5) "hello"
88  [2]=>
89  string(5) "world"
90  [3]=>
91  int(1)
92  [4]=>
93  int(2)
94}
95-- Iteration 2 --
96int(3)
97array(3) {
98  [0]=>
99  int(10)
100  [1]=>
101  float(1.1)
102  [2]=>
103  float(2.2)
104}
105int(5)
106array(5) {
107  [0]=>
108  int(10)
109  [1]=>
110  string(5) "hello"
111  [2]=>
112  string(5) "world"
113  [3]=>
114  float(1.1)
115  [4]=>
116  float(2.2)
117}
118-- Iteration 3 --
119int(3)
120array(3) {
121  [0]=>
122  int(10)
123  [1]=>
124  array(1) {
125    [0]=>
126    int(2)
127  }
128  [2]=>
129  array(1) {
130    [0]=>
131    int(1)
132  }
133}
134int(5)
135array(5) {
136  [0]=>
137  int(10)
138  [1]=>
139  string(5) "hello"
140  [2]=>
141  string(5) "world"
142  [3]=>
143  array(1) {
144    [0]=>
145    int(2)
146  }
147  [4]=>
148  array(1) {
149    [0]=>
150    int(1)
151  }
152}
153-- Iteration 4 --
154int(3)
155array(3) {
156  [0]=>
157  int(10)
158  [1]=>
159  bool(false)
160  [2]=>
161  bool(true)
162}
163int(5)
164array(5) {
165  [0]=>
166  int(10)
167  [1]=>
168  string(5) "hello"
169  [2]=>
170  string(5) "world"
171  [3]=>
172  bool(false)
173  [4]=>
174  bool(true)
175}
176-- Iteration 5 --
177int(1)
178array(1) {
179  [0]=>
180  int(10)
181}
182int(3)
183array(3) {
184  [0]=>
185  int(10)
186  [1]=>
187  string(5) "hello"
188  [2]=>
189  string(5) "world"
190}
191-- Iteration 6 --
192int(2)
193array(2) {
194  [0]=>
195  int(10)
196  [1]=>
197  NULL
198}
199int(4)
200array(4) {
201  [0]=>
202  int(10)
203  [1]=>
204  string(5) "hello"
205  [2]=>
206  string(5) "world"
207  [3]=>
208  NULL
209}
210-- Iteration 7 --
211int(7)
212array(7) {
213  [0]=>
214  int(10)
215  [1]=>
216  string(1) "a"
217  [2]=>
218  string(4) "aaaa"
219  [3]=>
220  string(1) "b"
221  [4]=>
222  string(4) "bbbb"
223  [5]=>
224  string(1) "c"
225  [6]=>
226  string(5) "ccccc"
227}
228int(9)
229array(9) {
230  [0]=>
231  int(10)
232  [1]=>
233  string(5) "hello"
234  [2]=>
235  string(5) "world"
236  [3]=>
237  string(1) "a"
238  [4]=>
239  string(4) "aaaa"
240  [5]=>
241  string(1) "b"
242  [6]=>
243  string(4) "bbbb"
244  [7]=>
245  string(1) "c"
246  [8]=>
247  string(5) "ccccc"
248}
249-- Iteration 8 --
250int(4)
251array(4) {
252  [0]=>
253  int(10)
254  [1]=>
255  string(3) "one"
256  [2]=>
257  string(3) "two"
258  [3]=>
259  string(5) "three"
260}
261int(6)
262array(6) {
263  [0]=>
264  int(10)
265  [1]=>
266  string(5) "hello"
267  [2]=>
268  string(5) "world"
269  [3]=>
270  string(3) "one"
271  [4]=>
272  string(3) "two"
273  [5]=>
274  string(5) "three"
275}
276-- Iteration 9 --
277int(4)
278array(4) {
279  [0]=>
280  int(10)
281  ["one"]=>
282  int(1)
283  ["two"]=>
284  int(2)
285  ["three"]=>
286  int(3)
287}
288int(6)
289array(6) {
290  [0]=>
291  int(10)
292  [1]=>
293  string(5) "hello"
294  [2]=>
295  string(5) "world"
296  ["one"]=>
297  int(1)
298  ["two"]=>
299  int(2)
300  ["three"]=>
301  int(3)
302}
303-- Iteration 10 --
304int(5)
305array(5) {
306  [0]=>
307  int(10)
308  [1]=>
309  int(10)
310  [2]=>
311  int(20)
312  [3]=>
313  int(40)
314  [4]=>
315  int(30)
316}
317int(7)
318array(7) {
319  [0]=>
320  int(10)
321  [1]=>
322  string(5) "hello"
323  [2]=>
324  string(5) "world"
325  [3]=>
326  int(10)
327  [4]=>
328  int(20)
329  [5]=>
330  int(40)
331  [6]=>
332  int(30)
333}
334-- Iteration 11 --
335int(4)
336array(4) {
337  [0]=>
338  int(10)
339  ["one"]=>
340  string(3) "ten"
341  ["two"]=>
342  string(6) "twenty"
343  ["three"]=>
344  string(6) "thirty"
345}
346int(6)
347array(6) {
348  [0]=>
349  int(10)
350  [1]=>
351  string(5) "hello"
352  [2]=>
353  string(5) "world"
354  ["one"]=>
355  string(3) "ten"
356  ["two"]=>
357  string(6) "twenty"
358  ["three"]=>
359  string(6) "thirty"
360}
361-- Iteration 12 --
362int(4)
363array(4) {
364  [0]=>
365  int(10)
366  ["one"]=>
367  int(1)
368  [1]=>
369  string(3) "two"
370  [2]=>
371  string(4) "four"
372}
373int(6)
374array(6) {
375  [0]=>
376  int(10)
377  [1]=>
378  string(5) "hello"
379  [2]=>
380  string(5) "world"
381  ["one"]=>
382  int(1)
383  [3]=>
384  string(3) "two"
385  [4]=>
386  string(4) "four"
387}
388-- Iteration 13 --
389int(4)
390array(4) {
391  [0]=>
392  int(10)
393  [""]=>
394  string(4) "null"
395  ["NULL"]=>
396  NULL
397  ["null"]=>
398  NULL
399}
400int(6)
401array(6) {
402  [0]=>
403  int(10)
404  [1]=>
405  string(5) "hello"
406  [2]=>
407  string(5) "world"
408  [""]=>
409  string(4) "null"
410  ["NULL"]=>
411  NULL
412  ["null"]=>
413  NULL
414}
415-- Iteration 14 --
416int(5)
417array(5) {
418  [0]=>
419  int(10)
420  [1]=>
421  string(4) "true"
422  [2]=>
423  string(5) "false"
424  ["false"]=>
425  bool(false)
426  ["true"]=>
427  bool(true)
428}
429int(7)
430array(7) {
431  [0]=>
432  int(10)
433  [1]=>
434  string(5) "hello"
435  [2]=>
436  string(5) "world"
437  [3]=>
438  string(4) "true"
439  [4]=>
440  string(5) "false"
441  ["false"]=>
442  bool(false)
443  ["true"]=>
444  bool(true)
445}
446-- Iteration 15 --
447int(4)
448array(4) {
449  [0]=>
450  int(10)
451  [""]=>
452  string(6) "emptys"
453  ["emptyd"]=>
454  string(0) ""
455  ["emptys"]=>
456  string(0) ""
457}
458int(6)
459array(6) {
460  [0]=>
461  int(10)
462  [1]=>
463  string(5) "hello"
464  [2]=>
465  string(5) "world"
466  [""]=>
467  string(6) "emptys"
468  ["emptyd"]=>
469  string(0) ""
470  ["emptys"]=>
471  string(0) ""
472}
473-- Iteration 16 --
474int(7)
475array(7) {
476  [0]=>
477  int(10)
478  [1]=>
479  string(0) ""
480  [2]=>
481  string(0) ""
482  [3]=>
483  NULL
484  [4]=>
485  NULL
486  [5]=>
487  bool(false)
488  [6]=>
489  bool(true)
490}
491int(9)
492array(9) {
493  [0]=>
494  int(10)
495  [1]=>
496  string(5) "hello"
497  [2]=>
498  string(5) "world"
499  [3]=>
500  string(0) ""
501  [4]=>
502  string(0) ""
503  [5]=>
504  NULL
505  [6]=>
506  NULL
507  [7]=>
508  bool(false)
509  [8]=>
510  bool(true)
511}
512-- Iteration 17 --
513int(4)
514array(4) {
515  [0]=>
516  int(10)
517  [""]=>
518  int(4)
519  [1]=>
520  int(5)
521  [2]=>
522  int(6)
523}
524int(6)
525array(6) {
526  [0]=>
527  int(10)
528  [1]=>
529  string(5) "hello"
530  [2]=>
531  string(5) "world"
532  [""]=>
533  int(4)
534  [3]=>
535  int(5)
536  [4]=>
537  int(6)
538}
539-- Iteration 18 --
540int(4)
541array(4) {
542  [0]=>
543  int(10)
544  ["One"]=>
545  int(10)
546  ["two"]=>
547  int(20)
548  ["three"]=>
549  int(3)
550}
551int(6)
552array(6) {
553  [0]=>
554  int(10)
555  [1]=>
556  string(5) "hello"
557  [2]=>
558  string(5) "world"
559  ["One"]=>
560  int(10)
561  ["two"]=>
562  int(20)
563  ["three"]=>
564  int(3)
565}
566Done
567