1--TEST--
2Test array_map() function : usage variations - associative array with different keys
3--FILE--
4<?php
5/*
6 * Test array_map() by passing associative array with different keys for $arr1 argument
7 */
8
9echo "*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***\n";
10
11function callback($a)
12{
13  return ($a);
14}
15
16// get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// get a resource variable
21$fp = fopen(__FILE__, "r");
22
23// get a class
24class classA{
25  public function __toString(){
26    return "Class A object";
27  }
28}
29
30// get a heredoc string
31$heredoc = <<<EOT
32Hello world
33EOT;
34
35// initializing the array
36$arrays = array (
37
38       // empty array
39/*1*/  array(),
40
41       // arrays with integer keys
42/*2*/  array(0 => "0"),
43       array(1 => "1"),
44       array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
45
46       // arrays with float keys
47/*5*/  array(2.3333 => "float"),
48       array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"),
49
50       // arrays with string keys
51       array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33),
52/*8*/  array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
53       array("hello", $heredoc => "string"), // heredoc
54
55       // array with object, unset variable and resource variable
56       array(@$unset_var => "hello", $fp => 'resource'),
57
58       // array with mixed values
59/*11*/ array('hello' => 1, "fruit" => 2.2,
60              $fp => 'resource', 133 => "int", 444.432 => "float",
61              @$unset_var => "unset", $heredoc => "heredoc")
62);
63
64// loop through the various elements of $arrays to test array_map()
65$iterator = 1;
66foreach($arrays as $arr1) {
67  echo "-- Iteration $iterator --\n";
68  var_dump( array_map('callback', $arr1) );
69  $iterator++;
70}
71
72echo "Done";
73?>
74--EXPECTF--
75*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***
76
77Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
78
79Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
80-- Iteration 1 --
81array(0) {
82}
83-- Iteration 2 --
84array(1) {
85  [0]=>
86  string(1) "0"
87}
88-- Iteration 3 --
89array(1) {
90  [1]=>
91  string(1) "1"
92}
93-- Iteration 4 --
94array(4) {
95  [1]=>
96  string(1) "1"
97  [2]=>
98  string(1) "2"
99  [3]=>
100  string(1) "3"
101  [4]=>
102  string(1) "4"
103}
104-- Iteration 5 --
105array(1) {
106  [2]=>
107  string(5) "float"
108}
109-- Iteration 6 --
110array(4) {
111  [1]=>
112  string(2) "f1"
113  [3]=>
114  string(2) "f2"
115  [4]=>
116  string(2) "f3"
117  [33333333]=>
118  string(2) "f4"
119}
120-- Iteration 7 --
121array(4) {
122  ["\tHello"]=>
123  int(111)
124  ["re\td"]=>
125  string(5) "color"
126  ["\v\fworld"]=>
127  float(2.2)
128  ["pen\n"]=>
129  int(33)
130}
131-- Iteration 8 --
132array(4) {
133  ["	Hello"]=>
134  int(111)
135  ["re	d"]=>
136  string(5) "color"
137  ["world"]=>
138  float(2.2)
139  ["pen
140"]=>
141  int(33)
142}
143-- Iteration 9 --
144array(2) {
145  [0]=>
146  string(5) "hello"
147  ["Hello world"]=>
148  string(6) "string"
149}
150-- Iteration 10 --
151array(2) {
152  [""]=>
153  string(5) "hello"
154  [5]=>
155  string(8) "resource"
156}
157-- Iteration 11 --
158array(7) {
159  ["hello"]=>
160  int(1)
161  ["fruit"]=>
162  float(2.2)
163  [5]=>
164  string(8) "resource"
165  [133]=>
166  string(3) "int"
167  [444]=>
168  string(5) "float"
169  [""]=>
170  string(5) "unset"
171  ["Hello world"]=>
172  string(7) "heredoc"
173}
174Done
175