Question about array_walk & lt ;? Php $ fruits & nbsp; array (d & gt; lemon, a & gt; apple, B & gt; banana, c & gt; orange); function & nbsp; test_alter (& amp; $ item1, $ key, $ prefix) {$ item1 & nbs about array_walk
$ Fruits = array ("d" => "lemon", "a" => "apple", "B" => "banana ", "c" => "orange ");
Function test_alter (& $ item1, $ key, $ prefix)
{
$ Item1 = "$ prefix: $ item1 ";
}
Function test_print ($ item2, $ key)
{
Echo "$ key. $ item2
\ N ";
}
Echo "Before... \ n ";
Array_walk ($ fruits, 'Test _ print ');
Array_walk ($ fruits, 'Test _ alter ', 'fruit ');
Echo "... and after: \ n ";
Array_walk ($ fruits, 'Test _ print ');
?>
The traversal expression of the last few lines of this code cannot be understood. please help me analyze it carefully for me to understand it ~
Share: More
------ Solution --------------------
Array_walk ($ fruits, 'Test _ print ');
Use the callback function test_print to print every member of the array $ fruits.
Equivalent
Foreach ($ fruits as $ k => $ v) test_print ($ v, $ k );
Array_walk ($ fruits, 'Test _ alter ', 'fruit ');
Use the callback function test_alter to add 'fruit. 'to the front of each member value of the array $ fruits .'
Equivalent
Foreach ($ fruits as $ k => $ v) $ fruits [$ k] = test_alter ($ v, 'fruit ');