1--TEST--
2Test array_fill() function : usage variations - different types of array values for 'val' argument
3--FILE--
4<?php
5/* Prototype  : array array_fill(int $start_key, int $num, mixed $val)
6 * Description: Create an array containing num elements starting with index start_key each initialized to val
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * testing array_fill() by passing different types of array  values for 'val' argument
12 */
13
14echo "*** Testing array_fill() : usage variations ***\n";
15
16// Initialise function arguments not being substituted
17$start_key = 0;
18$num = 2;
19
20
21//array of different types of array values for 'val' argument
22$values = array(
23
24  /* 1  */  array(),
25            array(1 , 2 , 3 , 4),
26            array(1 => "Hi" , 2 => "Hello"),
27            array("Saffron" , "White" , "Green"),
28  /* 5  */  array('color' => 'red' , 'item' => 'pen'),
29            array( 'color' => 'red' , 2 => 'green ' ),
30            array("colour" => "red" , "item" => "pen"),
31            array( TRUE => "red" , FALSE => "green" ),
32            array( true => "red" , FALSE => "green" ),
33  /* 10 */  array( 1 => "Hi" , "color" => "red" , 'item' => 'pen'),
34            array( NULL => "Hi", '1' => "Hello" , "1" => "Green"),
35            array( ""=>1, "color" => "green"),
36  /* 13 */  array('Saffron' , 'White' , 'Green')
37);
38
39// loop through each element of the values array for 'val' argument
40// check the working of array_fill()
41echo "--- Testing array_fill() with different types of array values for 'val' argument ---\n";
42$counter = 1;
43for($i = 0; $i < count($values); $i++)
44{
45  echo "-- Iteration $counter --\n";
46  $val = $values[$i];
47
48  var_dump( array_fill($start_key , $num , $val) );
49
50  $counter++;
51}
52
53echo "Done";
54?>
55--EXPECTF--
56*** Testing array_fill() : usage variations ***
57--- Testing array_fill() with different types of array values for 'val' argument ---
58-- Iteration 1 --
59array(2) {
60  [0]=>
61  array(0) {
62  }
63  [1]=>
64  array(0) {
65  }
66}
67-- Iteration 2 --
68array(2) {
69  [0]=>
70  array(4) {
71    [0]=>
72    int(1)
73    [1]=>
74    int(2)
75    [2]=>
76    int(3)
77    [3]=>
78    int(4)
79  }
80  [1]=>
81  array(4) {
82    [0]=>
83    int(1)
84    [1]=>
85    int(2)
86    [2]=>
87    int(3)
88    [3]=>
89    int(4)
90  }
91}
92-- Iteration 3 --
93array(2) {
94  [0]=>
95  array(2) {
96    [1]=>
97    string(2) "Hi"
98    [2]=>
99    string(5) "Hello"
100  }
101  [1]=>
102  array(2) {
103    [1]=>
104    string(2) "Hi"
105    [2]=>
106    string(5) "Hello"
107  }
108}
109-- Iteration 4 --
110array(2) {
111  [0]=>
112  array(3) {
113    [0]=>
114    string(7) "Saffron"
115    [1]=>
116    string(5) "White"
117    [2]=>
118    string(5) "Green"
119  }
120  [1]=>
121  array(3) {
122    [0]=>
123    string(7) "Saffron"
124    [1]=>
125    string(5) "White"
126    [2]=>
127    string(5) "Green"
128  }
129}
130-- Iteration 5 --
131array(2) {
132  [0]=>
133  array(2) {
134    ["color"]=>
135    string(3) "red"
136    ["item"]=>
137    string(3) "pen"
138  }
139  [1]=>
140  array(2) {
141    ["color"]=>
142    string(3) "red"
143    ["item"]=>
144    string(3) "pen"
145  }
146}
147-- Iteration 6 --
148array(2) {
149  [0]=>
150  array(2) {
151    ["color"]=>
152    string(3) "red"
153    [2]=>
154    string(6) "green "
155  }
156  [1]=>
157  array(2) {
158    ["color"]=>
159    string(3) "red"
160    [2]=>
161    string(6) "green "
162  }
163}
164-- Iteration 7 --
165array(2) {
166  [0]=>
167  array(2) {
168    ["colour"]=>
169    string(3) "red"
170    ["item"]=>
171    string(3) "pen"
172  }
173  [1]=>
174  array(2) {
175    ["colour"]=>
176    string(3) "red"
177    ["item"]=>
178    string(3) "pen"
179  }
180}
181-- Iteration 8 --
182array(2) {
183  [0]=>
184  array(2) {
185    [1]=>
186    string(3) "red"
187    [0]=>
188    string(5) "green"
189  }
190  [1]=>
191  array(2) {
192    [1]=>
193    string(3) "red"
194    [0]=>
195    string(5) "green"
196  }
197}
198-- Iteration 9 --
199array(2) {
200  [0]=>
201  array(2) {
202    [1]=>
203    string(3) "red"
204    [0]=>
205    string(5) "green"
206  }
207  [1]=>
208  array(2) {
209    [1]=>
210    string(3) "red"
211    [0]=>
212    string(5) "green"
213  }
214}
215-- Iteration 10 --
216array(2) {
217  [0]=>
218  array(3) {
219    [1]=>
220    string(2) "Hi"
221    ["color"]=>
222    string(3) "red"
223    ["item"]=>
224    string(3) "pen"
225  }
226  [1]=>
227  array(3) {
228    [1]=>
229    string(2) "Hi"
230    ["color"]=>
231    string(3) "red"
232    ["item"]=>
233    string(3) "pen"
234  }
235}
236-- Iteration 11 --
237array(2) {
238  [0]=>
239  array(2) {
240    [""]=>
241    string(2) "Hi"
242    [1]=>
243    string(5) "Green"
244  }
245  [1]=>
246  array(2) {
247    [""]=>
248    string(2) "Hi"
249    [1]=>
250    string(5) "Green"
251  }
252}
253-- Iteration 12 --
254array(2) {
255  [0]=>
256  array(2) {
257    [""]=>
258    int(1)
259    ["color"]=>
260    string(5) "green"
261  }
262  [1]=>
263  array(2) {
264    [""]=>
265    int(1)
266    ["color"]=>
267    string(5) "green"
268  }
269}
270-- Iteration 13 --
271array(2) {
272  [0]=>
273  array(3) {
274    [0]=>
275    string(7) "Saffron"
276    [1]=>
277    string(5) "White"
278    [2]=>
279    string(5) "Green"
280  }
281  [1]=>
282  array(3) {
283    [0]=>
284    string(7) "Saffron"
285    [1]=>
286    string(5) "White"
287    [2]=>
288    string(5) "Green"
289  }
290}
291Done
292