blob: 9cad3668d53404695a1361ec3b41fd227c0635c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
--TEST--
Test array_map() function : usage variations - with recursive callback
--FILE--
<?php
/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] )
* Description: Applies the callback to the elements of the given arrays
* Source code: ext/standard/array.c
*/
/*
* Test array_map() by passing subarrays and recursive callback function
*/
echo "*** Testing array_map() : recursive callback function ***\n";
// callback function
function square_recur_single_array($var) {
if (is_array($var))
return array_map('square_recur_single_array', $var);
return $var * $var;
}
$array1 = array(1, array(2, 3, array(5)), array(4));
var_dump( array_map('square_recur_single_array', $array1));
echo "Done";
?>
--EXPECTF--
*** Testing array_map() : recursive callback function ***
array(3) {
[0]=>
int(1)
[1]=>
array(3) {
[0]=>
int(4)
[1]=>
int(9)
[2]=>
array(1) {
[0]=>
int(25)
}
}
[2]=>
array(1) {
[0]=>
int(16)
}
}
Done
|