1--TEST--
2Test array_walk() function : usage variations - 'input' argument as diff. associative arrays
3--FILE--
4<?php
5/*
6 * Passing 'input' argument as an associative array
7 *    with Numeric & string keys
8*/
9
10echo "*** Testing array_walk() : 'input' as an associative array ***\n";
11
12function for_numeric($value, $key, $user_data)
13{
14  // dump the input values to see if they are
15  // passed with correct type
16  var_dump($key);
17  var_dump($value);
18  var_dump($user_data);
19  echo "\n"; // new line to separate the output between each element
20}
21
22function for_string($value, $key)
23{
24  // dump the input values to see if they are
25  // passed with correct type
26  var_dump($key);
27  var_dump($value);
28  echo "\n"; // new line to separate the output between each element
29}
30
31function for_mixed($value, $key)
32{
33  // dump the input values to see if they are
34  // passed with correct type
35  var_dump($key);
36  var_dump($value);
37  echo "\n"; // new line to separate the output between each element
38}
39
40// Numeric keys
41$input = array( 1 => 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30);
42echo "-- Associative array with numeric keys --\n";
43var_dump( array_walk($input, "for_numeric", 10));
44
45// String keys
46$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange");
47echo "-- Associative array with string keys --\n";
48var_dump( array_walk($input, "for_string"));
49
50// binary keys
51$input = array( b"a" => "Apple", b"b" => "Banana");
52echo "-- Associative array with binary keys --\n";
53var_dump( array_walk($input, "for_string"));
54
55// Mixed keys - numeric/string
56$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3);
57echo "-- Associative array with numeric/string keys --\n";
58var_dump( array_walk($input, "for_mixed"));
59
60echo "Done"
61?>
62--EXPECT--
63*** Testing array_walk() : 'input' as an associative array ***
64-- Associative array with numeric keys --
65int(1)
66int(25)
67int(10)
68
69int(5)
70int(30)
71int(10)
72
73int(0)
74int(-80)
75int(10)
76
77int(-2)
78int(100)
79int(10)
80
81bool(true)
82-- Associative array with string keys --
83string(1) "a"
84string(5) "Apple"
85
86string(1) "b"
87string(7) "Bananna"
88
89string(1) "c"
90string(6) "carrot"
91
92string(1) "o"
93string(6) "Orange"
94
95bool(true)
96-- Associative array with binary keys --
97string(1) "a"
98string(5) "Apple"
99
100string(1) "b"
101string(6) "Banana"
102
103bool(true)
104-- Associative array with numeric/string keys --
105int(0)
106int(1)
107
108int(1)
109int(2)
110
111string(1) "a"
112string(5) "Apple"
113
114string(1) "b"
115string(6) "Banana"
116
117int(2)
118int(3)
119
120bool(true)
121Done
122