In-depth parsing of the foreach function in PHP _php tutorial

Source: Internet
Author: User
Foreach function (PHP4/PHP5)
foreachThe syntax structure provides an easy way to iterate through an array.
foreachCan only be applied to arrays and objects, if an attempt is made to apply a variable to another data type, or an uninitialized variable will emit an error message.

There are two kinds of syntax:
Copy the Code code as follows:
foreach (array_expression as $value)
Statement
foreach (array_expression as $key = $value)
Statement

Example 1:
Copy the Code code as follows:
$arr =array (1,2,3,4);
foreach ($arr as $value) {
echo $value. "
";
}
?>

Example 2:
Copy the Code code as follows:
$arr =array (1,2,3,4);
foreach ($arr as $key = = $value) {
echo $key. " =====> ". $value."
";
}
?>

http://www.bkjia.com/PHPjc/313669.html www.bkjia.com true http://www.bkjia.com/PHPjc/313669.html techarticle the foreach function (PHP4/PHP5) foreach syntax structure provides an easy way to iterate through an array. foreach can only be applied to arrays and objects if you try to apply variables to other data types ...

  • 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.