Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP break from 2 loops [duplicate]

Tags:

loops

php

break

I have problem with break from loops. I have code like this:

<?php
$return = array(...);
while(true) {
    foreach($return AS $row) {
        if($row['timer'] > 15)
            break;
    }
    sleep(2);
}

And I need break while(true)

like image 370
Vaflan Avatar asked Aug 27 '14 12:08

Vaflan


2 Answers

You can specify how many loop you want to break that way :

break 2;

So in your case :

while(true) {
    foreach($return AS $row) {
        if($row['timer'] > 15){
            break 2;
        }
    }
    sleep(2);
}
like image 96
Clément Malet Avatar answered Oct 31 '22 05:10

Clément Malet


$breakfromloop = false;
while(!$breakfromloop) {
    foreach($return AS $row) {
        if($row['timer'] > 15)
        {
            $breakfromloop = true;
        }
    }
    sleep(2);
}
like image 35
craig1231 Avatar answered Oct 31 '22 07:10

craig1231