1--TEST-- 2Test array_walk_recursive() function : basic functionality - associative array 3--FILE-- 4<?php 5echo "*** Testing array_walk_recursive() : basic functionality ***\n"; 6 7// associative array 8$fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple")); 9 10function test_alter(&$item, $key, $prefix) 11{ 12 // dump the arguments to check that they are passed 13 // with proper type 14 var_dump($item); // value 15 var_dump($key); // key 16 var_dump($prefix); // additional argument passed to callback function 17 echo "\n"; // new line to separate the output between each element 18} 19 20function 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 29echo "-- Using array_walk_recursive with default parameters to show array contents --\n"; 30var_dump(array_walk_recursive($fruits, 'test_print')); 31 32echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n"; 33var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit')); 34 35echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n"; 36var_dump (array_walk_recursive($fruits, 'test_print')); 37 38echo "Done"; 39?> 40--EXPECT-- 41*** Testing array_walk_recursive() : basic functionality *** 42-- Using array_walk_recursive with default parameters to show array contents -- 43string(5) "lemon" 44string(1) "a" 45 46string(6) "orange" 47string(1) "c" 48 49string(6) "banana" 50string(1) "d" 51 52string(5) "apple" 53string(1) "f" 54 55bool(true) 56-- Using array_walk_recursive with one optional parameter to modify contents -- 57string(5) "lemon" 58string(1) "a" 59string(5) "fruit" 60 61string(6) "orange" 62string(1) "c" 63string(5) "fruit" 64 65string(6) "banana" 66string(1) "d" 67string(5) "fruit" 68 69string(5) "apple" 70string(1) "f" 71string(5) "fruit" 72 73bool(true) 74-- Using array_walk_recursive with default parameters to show modified array contents -- 75string(5) "lemon" 76string(1) "a" 77 78string(6) "orange" 79string(1) "c" 80 81string(6) "banana" 82string(1) "d" 83 84string(5) "apple" 85string(1) "f" 86 87bool(true) 88Done 89