The foreach provides to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type. There are two syntaxes:
Syntax
foreach (array as $value){
// Code to be executed;
}
foreach (array as $key => $value){
// Code to be executed;
}
Example
$array=array(1,2,3,4);
foreach($array as $value){
echo $value;
}
Copyright ©2022 coderraj.com. All Rights Reserved.