Can I get some simplified explanation about semi-colon use in php?

117 Views Asked by At

I have seen some articles explaining that a semi colon is not required in the last line of a PHP code due to the closing PHP tag (?>). Is this the case or is there any other theory around it?

1

There are 1 best solutions below

0
On BEST ANSWER

A semicolon is to denote end of the instruction, and that a new one may start. When a closing tag is found, no new instructions are expected so it's technically not needed.

It's useful in cases like <?= 'foobar' ?> so you don't need to use a semicolon to echo out the string, but <?= 'foobar'; ?> works just as well.