Home > Backend Development > PHP Tutorial > foreach function in php_PHP tutorial

foreach function in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-14 10:12:11
Original
1136 people have browsed it

Foreach function (PHP4/PHP5)

The foreach syntax structure provides a simple way to traverse an array.
foreach can only be applied to arrays and objects. If you try to apply it to variables of other data types, or uninitialized variables, an error message will be issued.
has two syntaxes:
[php]
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement
Example 1:
[php]
$arr=array(1,2,3,4);
foreach($arr as $value){
echo $value."
";
}
?>
$arr=array(1,2,3,4);
foreach($arr as $value){
echo $value."
";
}
?>
Example 2:
[php]
$arr=array(1,2,3,4);
foreach($arr as $key=>$value){
echo $key."=====>".$value."
";
}
?>
$arr=array(1,2,3,4);
foreach($arr as $key=>$value){
echo $key."=====>".$value."
";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477218.htmlTechArticleForeach function (PHP4/PHP5) The foreach syntax structure provides a simple way to traverse an array. foreach can only be applied to arrays and objects. If you try to apply it to variables of other data types,...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template