1--TEST--
2Test array_map() function : usage variations - array with references
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 reference values for $arr1 argument
12 */
13
14echo "*** Testing array_map() : array with references for 'arr1' argument ***\n";
15
16function callback1($a)
17{
18  return ($a);
19}
20
21function callback_cat($a, $b)
22{
23  return ($a . $b);
24}
25
26// reference variables
27$value1 = 10;
28$value2 = "hello";
29$value3 = 0;
30$value4 = &$value2;
31
32// array containing reference variables
33$arr1 = array(
34  0 => 0,
35  1 => &$value4,
36  2 => &$value2,
37  3 => "hello",
38  4 => &$value3,
39  $value4 => &$value2
40);
41echo "-- with one array --\n";
42var_dump( array_map('callback1', $arr1) );
43
44echo "-- with two arrays --\n";
45var_dump( array_map('callback_cat', $arr1, $arr1) );
46
47echo "Done";
48?>
49--EXPECT--
50*** Testing array_map() : array with references for 'arr1' argument ***
51-- with one array --
52array(6) {
53  [0]=>
54  int(0)
55  [1]=>
56  string(5) "hello"
57  [2]=>
58  string(5) "hello"
59  [3]=>
60  string(5) "hello"
61  [4]=>
62  int(0)
63  ["hello"]=>
64  string(5) "hello"
65}
66-- with two arrays --
67array(6) {
68  [0]=>
69  string(2) "00"
70  [1]=>
71  string(10) "hellohello"
72  [2]=>
73  string(10) "hellohello"
74  [3]=>
75  string(10) "hellohello"
76  [4]=>
77  string(2) "00"
78  [5]=>
79  string(10) "hellohello"
80}
81Done
82