i tried to make the loop stop and only print 1 content inside their if, if the condition have been met but it always either print the condition more than one, have both condition printed, or the else statement doesn’t display anything. Any suggestion?
$tf = 'belom';
$tf2 = 'belom';
if ($tf == 'belom') {
foreach ($roles as $role) {
if (in_array("user", $role) && $tf == 'belom') {
print_r($role);
$tf = 'udah';
echo '<button type="button" class="btn btn-primary" >Primary</button>';
$tf2 = 'udah';
}elseif ($tf2 !== 'udah') {
echo '<button type="button" class="btn btn-primary" disabled>Primary</button>';
$tf2 = 'udah';
}
}
}
// }
Sorry for the grammar, i’m not really good with english.
Hope you guys understand.
3
Answers
Use break to end the execution of the
foreach
.Read the documentation for
break
keyword. You can use as below.