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