Annotation of embedaddon/php/ext/standard/tests/array/array_walk_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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: */
23: function print_value($value, $key, $count)
24: {
25: echo $count." : ".$key." ".$value."\n";
26: }
27:
28: echo "*** 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:
58: for($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: }
62: echo "Done"
63: ?>
64: --EXPECTF--
65: *** Testing array_walk() : 'input' array with different values***
66:
67: -- Iteration 1 --
68: 1 : 0 1
69: 1 : 1 0
70: 1 : 2 -10
71: 1 : 3 19
72: 1 : 4 -33
73: 1 : 5 90
74: 1 : 6 31
75: 1 : 7 -110
76: bool(true)
77:
78: -- Iteration 2 --
79: 2 : 0 3.4
80: 2 : 1 0.8
81: 2 : 2 -2.9
82: 2 : 3 625
83: 2 : 4 0.0082
84: bool(true)
85:
86: -- Iteration 3 --
87: 3 : 0 Mango
88: 3 : 1 Apple
89: 3 : 2 Orange
90: 3 : 3 Lemon
91: bool(true)
92:
93: -- Iteration 4 --
94: 4 : 0 1
95: 4 : 1
96: 4 : 2 1
97: 4 : 3
98: bool(true)
99:
100: -- Iteration 5 --
101: 5 : 0
102: 5 : 1
103: bool(true)
104:
105: -- Iteration 6 --
106: bool(true)
107:
108: -- Iteration 7 --
109: 7 : 0 binary
110: bool(true)
111:
112: -- Iteration 8 --
113: 8 : 0 16
114: 8 : 1 8.345
115: 8 : 2 Fruits
116: 8 : 3 1
117: 8 : 4
118: 8 : 5
119: 8 : 6 -98
120: 8 : 7 0.005
121: 8 : 8 banana
122: bool(true)
123: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>