1--TEST--
2Test array_walk() function : usage variations - 'input' array with different values
3--FILE--
4<?php
5/* Prototype  : bool array_walk(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() 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() : 'input' array with different values***\n";
29
30// different arrays as input
31$input_values = array(
32
33       // integer values
34/*1*/  array(1, 0, -10, 023, -041, 0x5A, 0X1F, -0x6E),
35
36       // float value
37       array(3.4, 0.8, -2.9, 6.25e2, 8.20E-3),
38
39       // string values
40       array('Mango', "Apple", 'Orange', "Lemon"),
41
42       // bool values
43/*4*/  array(true, false, TRUE, FALSE),
44
45       // null values
46       array(null, NULL),
47
48       // empty array
49       array(),
50
51       // binary array
52       array(b"binary"),
53
54       // mixed array
55/*8*/  array(16, 8.345, "Fruits", true, null, FALSE, -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($input_values[$count], "print_value", $count+1));
61}
62echo "Done"
63?>
64--EXPECT--
65*** Testing array_walk() : 'input' array with different values***
66
67-- Iteration 1 --
681 : 0 1
691 : 1 0
701 : 2 -10
711 : 3 19
721 : 4 -33
731 : 5 90
741 : 6 31
751 : 7 -110
76bool(true)
77
78-- Iteration 2 --
792 : 0 3.4
802 : 1 0.8
812 : 2 -2.9
822 : 3 625
832 : 4 0.0082
84bool(true)
85
86-- Iteration 3 --
873 : 0 Mango
883 : 1 Apple
893 : 2 Orange
903 : 3 Lemon
91bool(true)
92
93-- Iteration 4 --
944 : 0 1
954 : 1
964 : 2 1
974 : 3
98bool(true)
99
100-- Iteration 5 --
1015 : 0
1025 : 1
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 : 2 Fruits
1168 : 3 1
1178 : 4
1188 : 5
1198 : 6 -98
1208 : 7 0.005
1218 : 8 banana
122bool(true)
123Done
124