Questions about the Array_walk
$fruits = Array ("d" = "lemon", "a" and "Apple", "b" = "banana", "C" and "orange");
Function Test_alter (& $item 1, $key, $prefix)
{
$item 1 = "$prefix: $item 1";
}
function Test_print ($item 2, $key)
{
echo "$key. $item 2
\ n ";
}
echo "before.....\n";
Array_walk ($fruits, ' test_print ');
Array_walk ($fruits, ' test_alter ', ' fruit ');
echo "... and after:\n";
Array_walk ($fruits, ' test_print ');
?>
On the last few lines of this code, the traversal of the expression of understanding can not ask greatly to help me to analyze carefully let me understand ~
Share to: more
------Solution--------------------
Array_walk ($fruits, ' test_print ');
Test_print each member of an array $fruits with a callback function
Equivalent
foreach ($fruits as $k = $v) test_print ($v, $k);
Array_walk ($fruits, ' test_alter ', ' fruit ');
Use the callback function Test_alter to precede the value of each member of the array $fruits with the string ' fruit. '
Equivalent
foreach ($fruits as $k = + $v) $fruits [$k] = Test_alter ($v, ' fruit ');