import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-array / array_walk_basic2.php
blobb64939de58568ffb07f83b9d37684d8332fe1d24
1 <?php
2 /* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata])
3 * Description: Apply a user function to every member of an array
4 * Source code: ext/standard/array.c
5 */
7 echo "*** Testing array_walk() : basic functionality ***\n";
9 // associative array
10 $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
12 // User defined callback functions
13 /* Prototype : test_alter(mixed $item, mixed $key, string $prefix)
14 * Parameters : item - value in key/value pair
15 * key - key in key/value pair
16 * prefix - string to be added
17 * Description : alters the array values by appending prefix string
18 */
19 function test_alter(&$item, $key, $prefix)
21 // dump the arguments to check that they are passed
22 // with proper type
23 var_dump($item); // value
24 var_dump($key); // key
25 var_dump($prefix); // additional agument passed to callback function
26 echo "\n"; // new line to separate the output between each element
29 /* Prototype : test_print(mixed $item, mixed $key)
30 * Parameters : item - value in key/value pair
31 * key - key in key/value pair
32 * Description : prints the array values with keys
34 function test_print($item, $key)
36 // dump the arguments to check that they are passed
37 // with proper type
38 var_dump($item); // value
39 var_dump($key); // key
40 echo "\n"; // new line to separate the output between each element
43 echo "-- Using array_walk with default parameters to show array contents --\n";
44 var_dump(array_walk($fruits, 'test_print'));
46 echo "-- Using array_walk with one optional parameter to modify contents --\n";
47 var_dump (array_walk($fruits, 'test_alter', 'fruit'));
49 echo "-- Using array_walk with default parameters to show modified array contents --\n";
50 var_dump (array_walk($fruits, 'test_print'));
52 echo "Done";