Comments in PHP | PHP Tutorial for Beginners

PHP comments are used to describe a specific section of code so that other developers can understand the code. Comments in PHP can also be used to hide any code. We can hide any code using comments in realtime to stop the execution of a specific part.

PHP supports a single line and multi-line comments. PHP comments are similar to any other programming language like C/C++, Java, and Perl style (Unix shell-style) comments.

Comments in PHP  PHP tutorial for beginners

Why comments are used

  • Others developers can easily understand your code
  • We can write comments as a reminder for us. we can later check the code in an easy way.

Single-Line Comments

Single line comments are used to write a comment in a single line.

We can write single-line comments in two ways

  • // This is a single-line comment
  • # This is also single line comment

Syntax :

 // This is single-line comment
#  This is also single line comment 
echo "Welcome to single line comments";


Multi-Line Comments in PHP

In PHP, we can comments on multiple lines also. We can use /* */ to comment multiple lines.

1st line
2nd line
3rd line
4th line
echo "Welcome to multi line comment section";  

Posted in PHP

Leave a Reply

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