syntax error, unexpected token “break”

Description

break is a token that stop the current loop or switch, and proceed from the end of that loop. break is standalone expression, and cannot be part of another expression: this is why it is forbidden in the array, or the match command.

Example

<?php
    // break does not fit everwhere
    $a = [1 => break ];

    // break is for switch, not match
    $b = match($c) {
        1 => break,
    };

?>

Solutions

  • Remove the break, and find another way to jump out of the loop.