Annotation of embedaddon/php/ext/standard/tests/array/array_walk_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_walk() function : usage variations - 'input' array with subarray
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 an array having subarrays as elements
12: */
13:
14: echo "*** Testing array_walk() : array with subarray ***\n";
15:
16: // callback function
17: /* Prototype : callback(mixed $value, mixed $key)
18: * Parameters : $value - values in given 'input' array
19: * $key - keys in given 'input' array
20: * Description : It prints the count of an array elements, passed as argument
21: */
22: function callback($value, $key)
23: {
24: // dump the arguments to check that they are passed
25: // with proper type
26: var_dump($key); // key
27: var_dump($value); // value
28: echo "\n"; // new line to separate the output between each element
29: }
30:
31: $input = array(
32: array(),
33: array(1),
34: array(1,2,3),
35: array("Mango", "Orange"),
36: array(array(1, 2, 3))
37: );
38:
39: var_dump( array_walk( $input, "callback"));
40:
41: echo "Done"
42: ?>
43: --EXPECTF--
44: *** Testing array_walk() : array with subarray ***
45: int(0)
46: array(0) {
47: }
48:
49: int(1)
50: array(1) {
51: [0]=>
52: int(1)
53: }
54:
55: int(2)
56: array(3) {
57: [0]=>
58: int(1)
59: [1]=>
60: int(2)
61: [2]=>
62: int(3)
63: }
64:
65: int(3)
66: array(2) {
67: [0]=>
68: string(5) "Mango"
69: [1]=>
70: string(6) "Orange"
71: }
72:
73: int(4)
74: array(1) {
75: [0]=>
76: array(3) {
77: [0]=>
78: int(1)
79: [1]=>
80: int(2)
81: [2]=>
82: int(3)
83: }
84: }
85:
86: bool(true)
87: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>