July 10, 2017

Core PHP: Comments Syntax (1.3)

Comments

In PHP code, a comment is a line that is not executed as part of the program. You can use comments to communicate to others so they understand what you're doing, or as a reminder to yourself of what you did.

A single-line comment starts with // :
<?php
echo "<p>Hello World!</p>";
// This is a single-line comment
echo "<p>I am learning PHP!</p>";
echo "<p>This is my first program!</p>";
?>

Result: 
Example: php comments

Multi-Line Comments

Multi-line comments are used for composing comments that take more than a single line.
A multi-line comment begins with /* and ends with */.
<?php
echo "<p>Hello World!</p>";
/*
This is a multi-line comment block
that spans over
multiple lines
*/
echo "<p>I am learning PHP!</p>";
echo "<p>This is my first program!</p>";
?>

Adding comments as you write your code is a good practice. It helps others understand your thinking and makes it easier for you to recall your thought processes when you refer to your code later on.

No comments:

Post a Comment