For some reason, using the following means to loop an array resists its break statements and continues to loop recursively to the utmost last element of the array
function loop($target, $array) {
if($this) {
if(!isset($GLOBALS["loop"])) {
$GLOBALS["loop"]+=1;
$GLOBALS["arrayCount"] = count($array, COUNT_RECURSIVE);
}
}
$keys = array_keys($array);
$values = array_values($array);
for($i=0;$i<count($array);$i++) {
$GLOBALS["iteration"]+=1;
if($keys[$i] === $target) {
print "Found $target.<br>";
break;
}
if(is_array($array[$i])) {
loop($target, $array[$i]);
}
if($values[$i] === $target) {
print "Found $target.<br>";
break;
}
if($GLOBALS["iteration"] >= $GLOBALS["arrayCount"]) {
print "Looped array.<br>";
break;
}
}
Any help is greatly appreciated!
Solved: it required an exit statement to be appended, so thanks to the mysterious comment which disappeared for whatever reason! Although, it would be interesting to learn of why a break statement is insufficient to stop the recursive looping.