Comments in php – PHP Lessons

elephant_phpComments

Classic PHP programming tell us that the comments in the program should be 30% of the code. There are merely two kinds of comments: the so-called single-line and multi-line comments.

Here is the single-line comments:
<?php
# this is comment
// and this is comment also
phpinfo(); // one more comment here
?>

Comments are need you or other programmers who will be working with your code so they could understand what you were doing in a particular line of code. In this example the comment will be anything that starts from the grid or a double slash to the end of the line.

Here is an example of a multiline comment:

<?php
/* this is a comment.
everything inside is a comment
code phpinfo(); won't work in a comment.
*/
?>

Represented by a multi-line comment as a “slash asterisk (/ *)” and ends with “asterisk slash (* /).”

With the help of multi-line comments is convenient to write large sections of comments or turn off chunks of codes, for example if you do not want to delete them as they may be needed in the future, you can just comment it.

Leave a Reply

Your email address will not be published. Required fields are marked *