This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Kamil
over 10 years

What is for sign ; ?

In PHP, if I put in echo some sentence (between “ “), there is not any difference if I put sign ; before last tag, at the end or not. Sentence is diplayed anywere. So, why is there ; ?

Answer 52ac8b6980ff33fdcf0067be

1 vote

Permalink

So im not really clear on what you are asking but ill give it a shot anyway. It sounds like you are asking why including a semicolon is necessary when everything seems to work fine regardless of whether its there or not.

<?php echo "This works"; ?>
<?php echo "This works too even though there isnt a semicolon" ?>

Semicolons are optional when they are the very last statement in a codeblock. The reason you would want to include it even though its not required has to do with avoiding syntax errors in the future when the code is modified. You might not notice that the semicolon is missing and go on to add another statement after it, resulting in an error that you have to go back and fix. Its really a matter of preference, but when i’m writing code i usually prefer to spend a just a little more time up front to avoid problems later.

points
Submitted by Aaron Szymanski
over 10 years