How to Fix PHP Fatal error ‘break’ not in the ‘loop’ or ‘switch’ context

This type of error happen mostly in PHP versions 7.0 and higher.

It means that the break was used outside the for, foreach, while, or switch.

To fix it, you can use return false or die() to stop the code below instead.



$name = 'Anna';

if($name == 'Anna') {
    echo $name;
    return false;

echo 'Unknown name';


Output: Anna