1--TEST--
2Test array_map() function : usage variations - callback function with different return types
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 callback function returning:
12 *   int, string, bool, null values
13 */
14
15echo "*** Testing array_map() : callback with diff return value ***\n";
16
17$array1 = array(1, 2, 3);
18$array2 = array(3, 4, 5);
19
20echo "-- with integer return value --\n";
21function callback_int($a, $b)
22{
23  return $a + $b;
24}
25var_dump( array_map('callback_int', $array1, $array2));
26
27echo "-- with string return value --\n";
28function callback_string($a, $b)
29{
30  return "$a"."$b";
31}
32var_dump( array_map('callback_string', $array1, $array2));
33
34echo "-- with bool return value --\n";
35function callback_bool($a, $b)
36{
37  return TRUE;
38}
39var_dump( array_map('callback_bool', $array1, $array2));
40
41echo "-- with null return value --\n";
42function callback_null($array1)
43{
44  return NULL;
45}
46var_dump( array_map('callback_null', $array1));
47
48echo "-- with no return value --\n";
49function callback_without_ret($arr1)
50{
51  echo "callback_without_ret called\n";
52}
53var_dump( array_map('callback_without_ret', $array1));
54
55echo "Done";
56?>
57--EXPECT--
58*** Testing array_map() : callback with diff return value ***
59-- with integer return value --
60array(3) {
61  [0]=>
62  int(4)
63  [1]=>
64  int(6)
65  [2]=>
66  int(8)
67}
68-- with string return value --
69array(3) {
70  [0]=>
71  string(2) "13"
72  [1]=>
73  string(2) "24"
74  [2]=>
75  string(2) "35"
76}
77-- with bool return value --
78array(3) {
79  [0]=>
80  bool(true)
81  [1]=>
82  bool(true)
83  [2]=>
84  bool(true)
85}
86-- with null return value --
87array(3) {
88  [0]=>
89  NULL
90  [1]=>
91  NULL
92  [2]=>
93  NULL
94}
95-- with no return value --
96callback_without_ret called
97callback_without_ret called
98callback_without_ret called
99array(3) {
100  [0]=>
101  NULL
102  [1]=>
103  NULL
104  [2]=>
105  NULL
106}
107Done
108