Annotation of embedaddon/php/ext/standard/tests/array/array_walk_basic1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_walk() function : basic functionality - regular array
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: echo "*** Testing array_walk() : basic functionality ***\n";
11:
12: // regular array
13: $fruits = array("lemon", "orange", "banana", "apple");
14:
15: /* Prototype : test_print(mixed $item, mixed $key)
16: * Parameters : item - item in key/item pair
17: * key - key in key/item pair
18: * Description : prints the array values with keys
19: */
20: function test_print($item, $key)
21: {
22: // dump the arguments to check that they are passed
23: // with proper type
24: var_dump($item); // value
25: var_dump($key); // key
26: echo "\n"; // new line to separate the output between each element
27: }
28: function with_userdata($item, $key, $user_data)
29: {
30: // dump the arguments to check that they are passed
31: // with proper type
32: var_dump($item); // value
33: var_dump($key); // key
34: var_dump($user_data); // user supplied data
35: echo "\n"; // new line to separate the output between each element
36: }
37:
38: echo "-- Using array_walk() with default parameters to show array contents --\n";
39: var_dump( array_walk($fruits, 'test_print'));
40:
41: echo "-- Using array_walk() with all parameters --\n";
42: var_dump( array_walk($fruits, 'with_userdata', "Added"));
43:
44: echo "Done";
45: ?>
46: --EXPECT--
47: *** Testing array_walk() : basic functionality ***
48: -- Using array_walk() with default parameters to show array contents --
49: string(5) "lemon"
50: int(0)
51:
52: string(6) "orange"
53: int(1)
54:
55: string(6) "banana"
56: int(2)
57:
58: string(5) "apple"
59: int(3)
60:
61: bool(true)
62: -- Using array_walk() with all parameters --
63: string(5) "lemon"
64: int(0)
65: string(5) "Added"
66:
67: string(6) "orange"
68: int(1)
69: string(5) "Added"
70:
71: string(6) "banana"
72: int(2)
73: string(5) "Added"
74:
75: string(5) "apple"
76: int(3)
77: string(5) "Added"
78:
79: bool(true)
80: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>