Things To Remember While Coding
1) Semicolons. Leaving out the semicolons will end up with “Parse error” while running your PHP script.
The semicolons completes a PHP statement. PHP reads a statement until the semicolon or the PHP closing tag. PHP doesn’t care how many lines of code you have written or how many blank spaces you have in your code. PHP checks the code until the next semicolon and treats everything before the semicolon as a single statement. Even though semicolons are not needed for the last PHP statement before the closing tag, It is always a good practice to put the semicolons at the end of each statements.
2) Dollar sign. A variable must start with a dollar($) sign. Make your script easier to understand by using descriptive variable names like $firstName, $address, $dateOfBirth instead of $var1, $var2, $var3. This will help you in troubleshooting the script. This will also make your script understandable by a third person.
3) Single/Double Quotes. Everything inside the single quotes are treated as plain string while things inside double quotes will parse the variables by replacing them with their values.
$firstName = "Sam"; echo 'Hello $firstName'; // Output: Hello $firstName echo "Hello $firstName"; // Output: Hello Sam
4) Keywords. Constants should not be given names that are PHP Keywords. Keywords have certain meaning and PHP treats them as PHP feature of the same name. Some of the PHP keyword are echo, print, continue, function etc.
To know more about it, visit our website.
















