1--TEST--
2Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_unshift() by giving two-dimensional
7 * arrays and also sub-arrays within the two-dimensional array for $array argument.
8 * The $var argument passed is a fixed value
9*/
10
11echo "*** Testing array_unshift() : two dimensional arrays for \$array argument ***\n";
12
13// initializing $var argument
14$var = 10;
15
16// two-dimensional array to be passed to $array argument
17$two_dimensional_array = array(
18
19   // associative array
20   array('color' => 'red', 'item' => 'pen', 'place' => 'LA'),
21
22   // numeric array
23   array(1, 2, 3, 4, 5),
24
25   // combination of numeric and associative arrays
26   array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball')
27);
28
29/* Passing the entire $two_dimensional_array to $array */
30
31/* With default argument */
32// returns element count in the resulting array after arguments are pushed to
33// beginning of the given array
34$temp_array = $two_dimensional_array;
35var_dump( array_unshift($temp_array, $var) );  // whole 2-d array
36
37// dumps the resulting array
38var_dump($temp_array);
39
40/* With optional arguments */
41// returns element count in the resulting array after arguments are pushed to
42// beginning of the given array
43$temp_array = $two_dimensional_array;
44var_dump( array_unshift($temp_array, $var, "hello", 'world') );  // whole 2-d array
45
46// dumps the resulting array
47var_dump($temp_array);
48
49/* Passing the sub-array within the $two_dimensional_array to $array argument */
50
51/* With default argument */
52// returns element count in the resulting array after arguments are pushed to
53// beginning of the given array
54$temp_array = $two_dimensional_array[0];
55var_dump( array_unshift($temp_array, $var) );  // sub array
56
57// dumps the resulting array
58var_dump($temp_array);
59
60/* With optional arguments */
61// returns element count in the resulting array after arguments are pushed to
62// beginning of the given array
63$temp_array = $two_dimensional_array[0];
64var_dump( array_unshift($temp_array, $var, "hello", 'world') );  // sub array
65
66// dumps the resulting array
67var_dump($temp_array);
68
69echo "Done";
70?>
71--EXPECT--
72*** Testing array_unshift() : two dimensional arrays for $array argument ***
73int(4)
74array(4) {
75  [0]=>
76  int(10)
77  [1]=>
78  array(3) {
79    ["color"]=>
80    string(3) "red"
81    ["item"]=>
82    string(3) "pen"
83    ["place"]=>
84    string(2) "LA"
85  }
86  [2]=>
87  array(5) {
88    [0]=>
89    int(1)
90    [1]=>
91    int(2)
92    [2]=>
93    int(3)
94    [3]=>
95    int(4)
96    [4]=>
97    int(5)
98  }
99  [3]=>
100  array(7) {
101    ["a"]=>
102    string(5) "green"
103    [0]=>
104    string(3) "red"
105    [1]=>
106    string(5) "brown"
107    [2]=>
108    int(33)
109    [3]=>
110    int(88)
111    [4]=>
112    string(6) "orange"
113    ["item"]=>
114    string(4) "ball"
115  }
116}
117int(6)
118array(6) {
119  [0]=>
120  int(10)
121  [1]=>
122  string(5) "hello"
123  [2]=>
124  string(5) "world"
125  [3]=>
126  array(3) {
127    ["color"]=>
128    string(3) "red"
129    ["item"]=>
130    string(3) "pen"
131    ["place"]=>
132    string(2) "LA"
133  }
134  [4]=>
135  array(5) {
136    [0]=>
137    int(1)
138    [1]=>
139    int(2)
140    [2]=>
141    int(3)
142    [3]=>
143    int(4)
144    [4]=>
145    int(5)
146  }
147  [5]=>
148  array(7) {
149    ["a"]=>
150    string(5) "green"
151    [0]=>
152    string(3) "red"
153    [1]=>
154    string(5) "brown"
155    [2]=>
156    int(33)
157    [3]=>
158    int(88)
159    [4]=>
160    string(6) "orange"
161    ["item"]=>
162    string(4) "ball"
163  }
164}
165int(4)
166array(4) {
167  [0]=>
168  int(10)
169  ["color"]=>
170  string(3) "red"
171  ["item"]=>
172  string(3) "pen"
173  ["place"]=>
174  string(2) "LA"
175}
176int(6)
177array(6) {
178  [0]=>
179  int(10)
180  [1]=>
181  string(5) "hello"
182  [2]=>
183  string(5) "world"
184  ["color"]=>
185  string(3) "red"
186  ["item"]=>
187  string(3) "pen"
188  ["place"]=>
189  string(2) "LA"
190}
191Done
192