Saturday, 2 January 2016

Statements and Semicolons

Statements and Semicolons:
 A statement is a collection of PHP code that does something. It can be as simple as a variable assignment or as complicated as a loop with multiple exit points.here is a small sample of PHP statements, including function calls, assignment, 
and an if test:
echo "Hello, world";
 myfunc(42, "O'Reilly");
 $a = 1; $name = "Elphaba"; 
$b = $a / 25.0;
 if ($a == $b) { echo "Rhyme? And Reason?"; }
PHP uses semicolons to separate simple statements. A compound statement that uses curly braces to mark a block of code, such as a conditional test or loop, does not need a semicolon after a closing brace. Unlike in other languages. 
In PHP the semico- lon before the closing brace is not optional:

if ($needed) {  echo "We must have it!";       // semicolon required here }                                        // no semicolon 

required here The semicolon is optional before a closing PHP tag:
<?php 
if ($a == $b) 
{ echo "Rhyme? And Reason?"; } 
echo "Hello, world"             // no semicolon required before closing tag ?>
 It’s good programming practice to include optional semicolons, as they make it easier to add code later.

No comments:

Post a Comment