Commenting In PHP
The PHP comment syntax always begins with a special character sequence and all text that appears between the start of the comment and the end will be ignored by the browser.
PHP’s comments will not be displayed to your visitors when they visit the your page. The only way to view PHP comments is to open the PHP file for editing. This makes PHP comments only useful to PHP programmers.
< ?php
// This is an example of Comment
echo "Hello!";
?>
Output :
Hello World!
Notice that line with // will not executed because we commented them out with the single line comment. This type of line commenting is often used for quick notes about complex and confusing code or to temporarily remove a line of PHP code.
Multiple Line Comment
The multi-line PHP comment can be used to comment out large blocks of code or writing multiple line comments. The multiple line PHP comment begins with ” /* ” and ends with ” */ “.
PHP Code:
< ?php
/* This is an example of Multi line comment
echo "Hello!";
echo "Friend!";
/*
echo "How are you?";
?>
Output:
How are you?
Always have Good Commenting Practices
One of the best practices that I can recommend to new PHP programmers is use comments. So many people write complex PHP code but they do not put good comments or believe the commenting is not needed. But when the code becomes more complex one can find difficult to solve the errors.
Two or ten years later, when you look back at some code you have written, with comments, you can easily understand why you did it that way as opposed to another. You will also remember your code much better with comments. Comments also help others, if they have to edit your code in the future.


