summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_walk_recursive_variation6.phpt
blob: dee4813e1ae51b8ba91e10cecd4709a34241d488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
--TEST--
Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays
--FILE--
<?php
/*
 * Passing 'input' argument as an associative array
 *    with Numeric & string keys
*/

echo "*** Testing array_walk_recursive() : 'input' as an associative array ***\n";

function for_numeric($value, $key, $user_data)
{
  // dump the input values to see if they are
  // passed with correct type
  var_dump($key);
  var_dump($value);
  var_dump($user_data);
  echo "\n"; // new line to separate the output between each element
}

function for_string($value, $key)
{
  // dump the input values to see if they are
  // passed with correct type
  var_dump($key);
  var_dump($value);
  echo "\n"; // new line to separate the output between each element
}

function for_mixed($value, $key)
{
  // dump the input values to see if they are
  // passed with correct type
  var_dump($key);
  var_dump($value);
  echo "\n"; // new line to separate the output between each element
}

// Numeric keys
$input = array( 0 => array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30));
echo "-- Associative array with numeric keys --\n";
var_dump( array_walk_recursive($input, "for_numeric", 10));

// String keys
$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange"));
echo "-- Associative array with string keys --\n";
var_dump( array_walk_recursive($input, "for_string"));

// binary key
$input = array( b"a" => "Apple", b"b" => "Banana");
echo "-- Associative array with binary keys --\n";
var_dump( array_walk_recursive($input, "for_string"));

// Mixed keys - numeric/string
$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3);
echo "-- Associative array with numeric/string keys --\n";
var_dump( array_walk_recursive($input, "for_mixed"));

echo "Done"
?>
--EXPECT--
*** Testing array_walk_recursive() : 'input' as an associative array ***
-- Associative array with numeric keys --
int(1)
int(25)
int(10)

int(5)
int(12)
int(10)

int(0)
int(-80)
int(10)

int(-2)
int(100)
int(10)

int(5)
int(30)
int(10)

bool(true)
-- Associative array with string keys --
string(1) "a"
string(5) "Apple"

string(1) "b"
string(7) "Bananna"

string(1) "c"
string(6) "carrot"

string(1) "o"
string(6) "Orange"

bool(true)
-- Associative array with binary keys --
string(1) "a"
string(5) "Apple"

string(1) "b"
string(6) "Banana"

bool(true)
-- Associative array with numeric/string keys --
int(0)
int(1)

int(1)
int(2)

string(1) "a"
string(5) "Apple"

string(1) "b"
string(6) "Banana"

int(2)
int(3)

bool(true)
Done