Related questions about the Array_walk

Source: Internet
Author: User
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 ');
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.