1--TEST--
2Test array_map() function : usage variations - arrays of different size
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 array having different size
12 *   1) first array as empty array
13 *   2) second array as empty array
14 *   3) second array shorter than first array
15 *   4) first array shorter than second array
16 *   5) one more array than callback function arguments
17 */
18
19echo "*** Testing array_map() : arrays with diff. size ***\n";
20
21function callback($a, $b)
22{
23  return array($a => $b);
24}
25
26// calling array_map with different arrays
27var_dump( array_map('callback', array(1, 2, 3), array()) );
28var_dump( array_map('callback', array(), array('a', 'b', 'c')) );
29var_dump( array_map('callback', array(1, 2, 3), array('a', 'b')) );
30var_dump( array_map('callback', array(012, 0x2F, 0X1A), array(2.3, 12.4e2)) );
31var_dump( array_map('callback', array(), array(1, 2, 3), array('a', 'b')) );  // passing more no. of arrays than callback function argument
32
33echo "Done";
34?>
35--EXPECT--
36*** Testing array_map() : arrays with diff. size ***
37array(3) {
38  [0]=>
39  array(1) {
40    [1]=>
41    NULL
42  }
43  [1]=>
44  array(1) {
45    [2]=>
46    NULL
47  }
48  [2]=>
49  array(1) {
50    [3]=>
51    NULL
52  }
53}
54array(3) {
55  [0]=>
56  array(1) {
57    [""]=>
58    string(1) "a"
59  }
60  [1]=>
61  array(1) {
62    [""]=>
63    string(1) "b"
64  }
65  [2]=>
66  array(1) {
67    [""]=>
68    string(1) "c"
69  }
70}
71array(3) {
72  [0]=>
73  array(1) {
74    [1]=>
75    string(1) "a"
76  }
77  [1]=>
78  array(1) {
79    [2]=>
80    string(1) "b"
81  }
82  [2]=>
83  array(1) {
84    [3]=>
85    NULL
86  }
87}
88array(3) {
89  [0]=>
90  array(1) {
91    [10]=>
92    float(2.3)
93  }
94  [1]=>
95  array(1) {
96    [47]=>
97    float(1240)
98  }
99  [2]=>
100  array(1) {
101    [26]=>
102    NULL
103  }
104}
105array(3) {
106  [0]=>
107  array(1) {
108    [""]=>
109    int(1)
110  }
111  [1]=>
112  array(1) {
113    [""]=>
114    int(2)
115  }
116  [2]=>
117  array(1) {
118    [""]=>
119    int(3)
120  }
121}
122Done
123