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