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