Have been scratching my head for a few hours on this, seems like a silly issue, but just can't find a solution.
Here's my sample code:
$continueLoop = true;
$colorsArray = array("red", "white", "blue");
while($continueLoop == true) {
$arrayCount = count($colorsArray);
for ($i=0; $i < $arrayCount; $i++) {
echo "evaluating ".$colorsArray[$i]."<br>";
if($colorsArray[$i] == "blue") {
array_push($colorsArray, "YELLOW");
break;
}
}
if(count($colorsArray) == 4) {
$continueLoop = false;
}
}
It outputs
red
white
blue
Basically I am adding a color "YELLOW" and then it should walk through the whole array again. But it's ignoring the newly added array item.
I know it does recognize the item, because the while loop will keep running until $colorsArray has 4 items (in the beginning it has only 3).
So why is it not Echo'ing "YELLOW"?
I've tried a few different solutions, just pushing the item using $array[], using foreach, array_values etc. etc.
Thank you
Update:
If i put
if(count($colorsArray) == 10) {
Still still won't print Yellow
$continueLoop = false;command...forand then set$continueLoop = falseso everything is done and it doesn't loop again to echo yellow.