1--TEST--
2Test array_walk_recursive() function : usage variations - 'input' array with different values
3--FILE--
4<?php
5/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
6 * Description: Apply a user function to every member of an array
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * Testing array_walk_recursive() with following types of 'input' arrays:
12 *    integer, float, string, bool, null, empty & mixed
13*/
14
15// callback function
16/*
17 * Prototype : print_value(mixed $value, int $key, int $count)
18 * Parameters : $value - array entries(values)
19 *              $key - keys in given input array
20 *              $count - extra parameter used as an index
21 * Description : prints the array values with keys and count value
22 */
23function print_value($value, $key, $count)
24{
25  echo  $count." : ".$key." ".$value."\n";
26}
27
28echo "*** Testing array_walk_recursive() : 'input' array with different values***\n";
29
30// different arrays as input
31$input_values = array(
32
33       // integer values
34/*1*/  array(array(1, 0, -10), array(023, -041), array(0x5A, 0X1F, -0x6E)),
35
36       // float value
37       array(array(3.4, 0.8, -2.9), array(6.25e2, 8.20E-3)),
38
39       // string values
40       array('Mango', array("Apple", 'Orange', "Lemon")),
41
42       // bool values
43/*4*/  array( array(true, false), array(TRUE, FALSE)),
44
45       // null values
46       array( array(null), array(NULL)),
47
48       // empty array
49       array(),
50
51       // binary array
52       array(array(b'binary')),
53
54       // mixed array
55/*8*/  array(16, 8.345, array("Fruits"), array(true, null), array(FALSE), array(-98, 0.005, 'banana'))
56);
57
58for($count = 0; $count < count($input_values); $count++) {
59  echo "\n-- Iteration ".($count + 1)." --\n";
60  var_dump( array_walk_recursive($input_values[$count], "print_value", $count+1));
61}
62echo "Done"
63?>
64--EXPECT--
65*** Testing array_walk_recursive() : 'input' array with different values***
66
67-- Iteration 1 --
681 : 0 1
691 : 1 0
701 : 2 -10
711 : 0 19
721 : 1 -33
731 : 0 90
741 : 1 31
751 : 2 -110
76bool(true)
77
78-- Iteration 2 --
792 : 0 3.4
802 : 1 0.8
812 : 2 -2.9
822 : 0 625
832 : 1 0.0082
84bool(true)
85
86-- Iteration 3 --
873 : 0 Mango
883 : 0 Apple
893 : 1 Orange
903 : 2 Lemon
91bool(true)
92
93-- Iteration 4 --
944 : 0 1
954 : 1
964 : 0 1
974 : 1
98bool(true)
99
100-- Iteration 5 --
1015 : 0
1025 : 0
103bool(true)
104
105-- Iteration 6 --
106bool(true)
107
108-- Iteration 7 --
1097 : 0 binary
110bool(true)
111
112-- Iteration 8 --
1138 : 0 16
1148 : 1 8.345
1158 : 0 Fruits
1168 : 0 1
1178 : 1
1188 : 0
1198 : 0 -98
1208 : 1 0.005
1218 : 2 banana
122bool(true)
123Done
124