1--TEST--
2Test array_walk_recursive() function : usage variations - different callback functions
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 * Passing different types of callback functions to array_walk_recursive()
12 *   without parameters
13 *   with less and more parameters
14*/
15
16echo "*** Testing array_walk_recursive() : callback function variation ***\n";
17
18$input = array(array('Apple', 'Banana'), 'Mango', array('Orange'));
19
20echo "-- callback function with both parameters --\n";
21function callback_two_parameter($value, $key)
22{
23   // dump the arguments to check that they are passed
24   // with proper type
25   var_dump($key);  // key
26   var_dump($value); // value
27   echo "\n"; // new line to separate the output between each element
28}
29var_dump( array_walk_recursive($input, 'callback_two_parameter'));
30
31echo "-- callback function with only one parameter --\n";
32function callback_one_parameter($value)
33{
34   // dump the arguments to check that they are passed
35   // with proper type
36   var_dump($value); // value
37   echo "\n"; // new line to separate the output between each element
38}
39var_dump( array_walk_recursive($input, 'callback_one_parameter'));
40
41echo "-- callback function without parameters --\n";
42function callback_no_parameter()
43{
44  echo "callback3() called\n";
45}
46var_dump( array_walk_recursive($input, 'callback_no_parameter'));
47
48echo "-- passing one more parameter to function with two parameters --\n";
49var_dump( array_walk_recursive($input, 'callback_two_parameter', 10));
50
51echo "Done"
52?>
53--EXPECTF--
54*** Testing array_walk_recursive() : callback function variation ***
55-- callback function with both parameters --
56int(0)
57string(5) "Apple"
58
59int(1)
60string(6) "Banana"
61
62int(1)
63string(5) "Mango"
64
65int(0)
66string(6) "Orange"
67
68bool(true)
69-- callback function with only one parameter --
70string(5) "Apple"
71
72string(6) "Banana"
73
74string(5) "Mango"
75
76string(6) "Orange"
77
78bool(true)
79-- callback function without parameters --
80callback3() called
81callback3() called
82callback3() called
83callback3() called
84bool(true)
85-- passing one more parameter to function with two parameters --
86int(0)
87string(5) "Apple"
88
89int(1)
90string(6) "Banana"
91
92int(1)
93string(5) "Mango"
94
95int(0)
96string(6) "Orange"
97
98bool(true)
99Done
100