As a programming and scripting language PHP provides the comments in order to add description and notes to the code. This description is called a comment and not executed or interpreted by PHP. PHP comments can be used to explain the function, variable, code block, etc.
Single-Line Comment with Hash Sign
Similar to the other programming and scripting languages like Pyhton PHP provides the
hash sign or
# as a single line comment creator. Hash sign is located at the start of the line and the complete line is interpreted as comment not a PHP code or statement which will be executed.
<?php # This is a singleline comment echo "This is a PHP statement"; ?>
Single-Line Comment with Double Slash
The most used singleline comment is the
double slash or
// . The double slash comment sign is inherited from the C and C++ programming languages. In order to create singleline comment the double slash is located at the start of the line.
<?php // This is a singleline comment echo "This is a PHP statement"; ?>
In line comments are similar to the single line comments where some part of the line is interpreted as comment and not executed as a PHP statement. From the start of the line to the comment sign is interpreted as PHP statement and after the comments sign is intpreted as PHP comment and not executed. The hash sign (#) or double slash (//) can be used as inline comment.
<?php echo "This is a PHP statement"; // This is inline comment echo "This is a PHP statement"; # This is inline comment too ?>
PHP provides the multiline comment which wraps multiple lines as comment. The
/* characters are used to set start of the multiline comment and
*/ characters are used to set end of the end of the multiline comment.
<?php /* This is multiline comment */ echo "This is a PHP statement"; echo "This is a PHP statement"; /* This is a multiline comment too */ ?>