| PHP - Foreach Function Control | | Print | |
PHP - Foreach Function Control
A foreach loop is used to loop through an array. Here are both forms of the syntax:
foreach(array_expression as $value) {
statements
}
foreach(array_expression as $value):
statements
endforeach;
This loops through the array_expression and assigns each value of the array to $value in turn. You can also get the key for each element with this syntax:
foreach(array_expression as $key=>$value) {
statements
}
The break and continue statements work with a foreach loop like they do with a for loop.
Published in Website, php - website
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment.
| Users' Comments (0) |
|
No comment posted




