Annotation of embedaddon/php/ext/standard/tests/array/array_walk_recursive_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_walk_recursive() function : usage variations - anonymous callback function
3: --FILE--
4: <?php
5: /* Prototype : proto bool array_walk_recursive(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: * Passing anonymous(run-time) callback function with following variations:
12: * with one parameter
13: * two parameters
14: * three parameters
15: * extra parameters
16: * without parameters
17: */
18:
19: echo "*** Testing array_walk_recursive() : anonymous function as callback ***\n";
20:
21: $input = array( array(2, 5), array(10, 0));
22:
23: echo "-- Anonymous function with one argument --\n";
24: var_dump( array_walk_recursive($input, create_function('$value', 'var_dump($value); echo "\n";')));
25:
26: echo "-- Anonymous function with two arguments --\n";
27: var_dump( array_walk_recursive($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";')));
28:
29: echo "-- Anonymous function with three arguments --\n";
30: var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10));
31:
32: echo "-- Anonymous function with one more argument --\n";
33: var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30));
34:
35: echo "-- Anonymous function with null argument --\n";
36: var_dump( array_walk_recursive( $input, create_function(null, 'echo "1\n";')));
37: echo "Done"
38: ?>
39: --EXPECTF--
40: *** Testing array_walk_recursive() : anonymous function as callback ***
41: -- Anonymous function with one argument --
42: int(2)
43:
44: int(5)
45:
46: int(10)
47:
48: int(0)
49:
50: bool(true)
51: -- Anonymous function with two arguments --
52: int(0)
53: int(2)
54:
55: int(1)
56: int(5)
57:
58: int(0)
59: int(10)
60:
61: int(1)
62: int(0)
63:
64: bool(true)
65: -- Anonymous function with three arguments --
66: int(0)
67: int(2)
68: int(10)
69:
70: int(1)
71: int(5)
72: int(10)
73:
74: int(0)
75: int(10)
76: int(10)
77:
78: int(1)
79: int(0)
80: int(10)
81:
82: bool(true)
83: -- Anonymous function with one more argument --
84:
85: Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d
86: NULL
87: -- Anonymous function with null argument --
88: 1
89: 1
90: 1
91: 1
92: bool(true)
93: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>