1--TEST--
2Test array_map() function : usage variations - associative array with different values
3--FILE--
4<?php
5/*
6 * Test array_map() by passing associative array with different values for $arr1 argument
7 */
8
9echo "*** Testing array_map() : associative array with diff. values for 'arr1' argument ***\n";
10
11function callback($a)
12{
13  return ($a);
14}
15//get an unset variable
16$unset_var = array(1, 2);
17unset ($unset_var);
18
19//get a resource variable
20$fp = fopen(__FILE__, "r");
21
22//get a class
23class classA
24{
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 values
42       array('0' => 0),
43       array("1" => 1),
44       array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
45
46       // arrays with float values
47/*5*/  array("float" => 2.3333),
48       array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333),
49
50       // arrays with string values
51       array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 =>  "pen\n"),
52/*8*/  array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 =>  'pen\n'),
53       array(1 => "hello", "heredoc" => $heredoc),
54
55       // array with object, unset variable and resource variable
56       array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
57
58       // array with mixed values
59/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit",
60             'resource' => $fp, "int" => 133, "float" => 444.432,
61             "unset" => @$unset_var, "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. values for 'arr1' argument ***
76-- Iteration 1 --
77array(0) {
78}
79-- Iteration 2 --
80array(1) {
81  [0]=>
82  int(0)
83}
84-- Iteration 3 --
85array(1) {
86  [1]=>
87  int(1)
88}
89-- Iteration 4 --
90array(4) {
91  ["one"]=>
92  int(1)
93  ["two"]=>
94  int(2)
95  ["three"]=>
96  int(3)
97  [4]=>
98  int(4)
99}
100-- Iteration 5 --
101array(1) {
102  ["float"]=>
103  float(2.3333)
104}
105-- Iteration 6 --
106array(4) {
107  ["f1"]=>
108  float(1.2)
109  ["f2"]=>
110  float(3.33)
111  [3]=>
112  float(4.89999922839999)
113  ["f4"]=>
114  float(33333333.3333)
115}
116-- Iteration 7 --
117array(4) {
118  [111]=>
119  string(6) "	Hello"
120  ["red"]=>
121  string(6) "col	or"
122  [2]=>
123  string(7) "world"
124  [3]=>
125  string(4) "pen
126"
127}
128-- Iteration 8 --
129array(4) {
130  [111]=>
131  string(7) "\tHello"
132  ["red"]=>
133  string(7) "col\tor"
134  [2]=>
135  string(9) "\v\fworld"
136  [3]=>
137  string(5) "pen\n"
138}
139-- Iteration 9 --
140array(2) {
141  [1]=>
142  string(5) "hello"
143  ["heredoc"]=>
144  string(11) "Hello world"
145}
146-- Iteration 10 --
147array(3) {
148  [11]=>
149  object(classA)#%d (0) {
150  }
151  ["unset"]=>
152  NULL
153  ["resource"]=>
154  resource(%d) of type (stream)
155}
156-- Iteration 11 --
157array(8) {
158  [1]=>
159  string(5) "hello"
160  [2]=>
161  object(classA)#%d (0) {
162  }
163  [222]=>
164  string(5) "fruit"
165  ["resource"]=>
166  resource(%d) of type (stream)
167  ["int"]=>
168  int(133)
169  ["float"]=>
170  float(444.432)
171  ["unset"]=>
172  NULL
173  ["heredoc"]=>
174  string(11) "Hello world"
175}
176Done
177