1--TEST--
2Test array_map() function : usage variations - different arrays for 'arr1' argument
3--FILE--
4<?php
5/*
6 * Test array_map() by passing different arrays for $arr1 argument
7 */
8
9echo "*** Testing array_map() : different arrays for 'arr1' argument ***\n";
10
11function callback($a)
12{
13  return ($a);
14}
15
16// different arrays
17$arrays = array (
18/*1*/  array(1, 2), // array with default keys and numeric values
19       array(1.1, 2.2), // array with default keys & float values
20       array( array(2), array(1)), // sub arrays
21       array(false,true), // array with default keys and boolean values
22       array(), // empty array
23       array(NULL), // array with NULL
24       array("a","aaaa","b","bbbb","c","ccccc"),
25
26       // associative arrays
27/*8*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
28       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
29       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
30       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
31       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
32
33       // associative array, containing null/empty/boolean values as key/value
34/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
35       array(true => "true", false => "false", "false" => false, "true" => true),
36       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
37       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
38       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
39
40       // array with repetitive keys
41/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
42);
43
44// loop through the various elements of $arrays to test array_map()
45$iterator = 1;
46foreach($arrays as $arr1) {
47  echo "-- Iteration $iterator --\n";
48  var_dump( array_map('callback', $arr1) );
49  $iterator++;
50}
51
52echo "Done";
53?>
54--EXPECT--
55*** Testing array_map() : different arrays for 'arr1' argument ***
56-- Iteration 1 --
57array(2) {
58  [0]=>
59  int(1)
60  [1]=>
61  int(2)
62}
63-- Iteration 2 --
64array(2) {
65  [0]=>
66  float(1.1)
67  [1]=>
68  float(2.2)
69}
70-- Iteration 3 --
71array(2) {
72  [0]=>
73  array(1) {
74    [0]=>
75    int(2)
76  }
77  [1]=>
78  array(1) {
79    [0]=>
80    int(1)
81  }
82}
83-- Iteration 4 --
84array(2) {
85  [0]=>
86  bool(false)
87  [1]=>
88  bool(true)
89}
90-- Iteration 5 --
91array(0) {
92}
93-- Iteration 6 --
94array(1) {
95  [0]=>
96  NULL
97}
98-- Iteration 7 --
99array(6) {
100  [0]=>
101  string(1) "a"
102  [1]=>
103  string(4) "aaaa"
104  [2]=>
105  string(1) "b"
106  [3]=>
107  string(4) "bbbb"
108  [4]=>
109  string(1) "c"
110  [5]=>
111  string(5) "ccccc"
112}
113-- Iteration 8 --
114array(3) {
115  [1]=>
116  string(3) "one"
117  [2]=>
118  string(3) "two"
119  [3]=>
120  string(5) "three"
121}
122-- Iteration 9 --
123array(3) {
124  ["one"]=>
125  int(1)
126  ["two"]=>
127  int(2)
128  ["three"]=>
129  int(3)
130}
131-- Iteration 10 --
132array(4) {
133  [1]=>
134  int(10)
135  [2]=>
136  int(20)
137  [4]=>
138  int(40)
139  [3]=>
140  int(30)
141}
142-- Iteration 11 --
143array(3) {
144  ["one"]=>
145  string(3) "ten"
146  ["two"]=>
147  string(6) "twenty"
148  ["three"]=>
149  string(6) "thirty"
150}
151-- Iteration 12 --
152array(3) {
153  ["one"]=>
154  int(1)
155  [2]=>
156  string(3) "two"
157  [4]=>
158  string(4) "four"
159}
160-- Iteration 13 --
161array(3) {
162  [""]=>
163  string(4) "null"
164  ["NULL"]=>
165  NULL
166  ["null"]=>
167  NULL
168}
169-- Iteration 14 --
170array(4) {
171  [1]=>
172  string(4) "true"
173  [0]=>
174  string(5) "false"
175  ["false"]=>
176  bool(false)
177  ["true"]=>
178  bool(true)
179}
180-- Iteration 15 --
181array(3) {
182  [""]=>
183  string(6) "emptys"
184  ["emptyd"]=>
185  string(0) ""
186  ["emptys"]=>
187  string(0) ""
188}
189-- Iteration 16 --
190array(6) {
191  [1]=>
192  string(0) ""
193  [2]=>
194  string(0) ""
195  [3]=>
196  NULL
197  [4]=>
198  NULL
199  [5]=>
200  bool(false)
201  [6]=>
202  bool(true)
203}
204-- Iteration 17 --
205array(3) {
206  [""]=>
207  int(4)
208  [0]=>
209  int(5)
210  [1]=>
211  int(6)
212}
213-- Iteration 18 --
214array(3) {
215  ["One"]=>
216  int(10)
217  ["two"]=>
218  int(20)
219  ["three"]=>
220  int(3)
221}
222Done
223