How to make sure the value is reset in foreach loop in PHP
- by kwokwai
Hi all,
I was writing a simple PHP page and a few foreach loops were used.
Here are the scripts:
$arrs = array("a", "b", "c");
foreach ($arrs as $arr) {
if(substr($arr,0,1)=="b")
{
echo "This is b";
}
} // ends of first foreach loop and I didn't use ifelse here
And when this foreach ends,
I wrote another foreach loop in which all the values in the foreach loop
was the same as previous foreach.
foreach ($arrs as $arr) {
if(substr($arr,0,1)=="c")
{
echo "This is c";
}
}
I am not sure if it is a good practice to have two foreach loops with same values and keys.
Will the values get overwritten in the first foreach loop?