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