1
How to interrupt a foreach
PHP based on a condition coming from the database after starting the loop?
$smtm = Connect::getInstance()->query("SELECT * FROM table WHERE num IS NULL");
foreach ($smtm->fetchAll() as $value) {
//aqui vai o comando a ser executado.
if (Connect::getInstance()->query("SELECT * FROM table WHERE num IS NULL")) {
//encerra o loop se não encontrar NULL
break;
}
}
Since the BD can be changed at runtime, I would like to break
if the seat query meets the condition during the loop.
Still outside the scope of your question! Break is enough to stop a repeat loop, the problem is in your condition for such, I suggest you review your code so you can understand yourself what you want.
– Mauro Alexandre