I have a snippet of PHP code like this:
while($attempts < $cycles) {
foreach($player_array as $player) {
if(isset($player['results']) && $player['results'] == 1) {
$player['results'] = player_search($f, $s, $t);
}
}
}
The idea is for each item in the array it calls a search function. If the search has nothing, it returns false, which SHOULD stop it from calling the search for the rest of the remaining cycles by changing the value of 'results'.
I'm assuming that setting $player['results'] as false does not actually set the correct variable for when it pulls it in on the next iteration.
How should i change my code to get this working properly?
EDIT:
Can I make clear that if a search in a function returns no results I do not want that function to be called again, I DO however want the same function to be used for the other searches if they still have results. Obviously once all player searches have no result i would ideally like to break the while loop too.
Use break 2; to exit both the foreach and the while
while($attempts < $cycles) {
foreach($player_array as $player) {
if(isset($player['results']) && $player['results'] == 1) {
$player['results'] = player_search($f, $s, $t);
break 2;
}
}
}
Example from the PHP Manual : http://php.net/manual/en/control-structures.break.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With