Grammar explorer

PHP 8.5 Production

matched-foreach-statement

Read left to right. Select any rule to explore it.

matched-foreach-statement railroad diagramRead left to right. Branches are alternatives, bypasses are optional, and loops repeat. Select a production to explore it. The EBNF and linked references follow below."foreach""("Explore production: expressionexpression"as"Explore production: foreach-targetforeach-target")"Explore production: matched-statementmatched-statement"foreach""("Explore production: expressionexpression"as"Explore production: foreach-targetforeach-target")"":"Explore production: inner-statement-listinner-statement-list"endforeach"";"
Production LiteralBranch: choiceBypass: optionalLoop: repeat
EBNF source
matched-foreach-statement =
    "foreach" , "(" , expression , "as" , foreach-target , ")" , matched-statement
    | "foreach" , "(" , expression , "as" , foreach-target , ")" , ":" ,
      inner-statement-list , "endforeach" , ";" ;
Referenced by 2

Take it with you

The grammar, in plain text.

For reading, building tools, and exploring PHP.
Free to use under the MIT license.

A shared understanding of PHP.

php-grammar is an open source project documenting PHP syntax in a consistent, tool-independent format. The EBNF describes syntax; the accompanying specification defines lexical rules and contextual constraints.

Explore the project and contribute