Foreach (array_expression as $value){
statement;
}
Foreach (array_expression as $key => $value){
statement;
}
for example
<?php
$arr = array(2,3,4,5) ;
foreach($arr as &$value){
$value = $value * 2;
}
//$arr now is array(4,6,8,10)
unset($value);//break the reference with the last element
//warning Reference of a $value and the last array element remain even after the foreach loop.It is recommended to destroy it by unset().
?>
<?php
$arr = array(”apply “,”orange”,”banana”);
reset($arr); //Set the internal pointer of an array to its first element
foreach($arr as $key => $value){
echo “Key:$key;Value:$value<br />\n”;
}
?>
Leave a comment
You must be logged in to post a comment.