PHP comment is the line or group of lines in PHP script that will not executed .There are several way to write comment.
One line PHP Comment
PHP supports this type of commenting by using two consecutive forward slashes(//) preceding any comment added.
Block Comment or C Style Comment
block comments can start with a forward slash followed by an asterisk (/*), then close with an asterisk followed by a forward slash (*/)..
What is the purpose of comment in PHP Script ?
In computer programming, a remark is a programmer-readable clarification or annotation in the supply code of a computer program. They are delivered with the reason of making the supply code simpler for people to understand, and are typically omitted by using compilers and interpreters.
In PHP, there are two types of comments that can be used to document and explain the code:
- Single-line comments: Single-line comments start with two forward slashes (//) and are used to add comments to a single line of code. Anything after the slashes is ignored by the PHP interpreter. For example:
// This is a single-line comment in PHP $name = "Son"; // This line sets the value of the $name variable to "John"
- Multi-line comments: Multi-line comments start with a forward slash followed by an asterisk (/) and end with an asterisk followed by a forward slash (/). They can be used to add comments that span multiple lines of code. For example:
/* This is a multi-line comment in PHP. It can span multiple lines of code and is often used to provide more detailed explanations of what the code is doing. */ $name = "John"; /* This line sets the value of the $name variable to "John" */
It’s a good practice to add comments to your PHP code to make it more readable and easier to understand for yourself and others who may be working with or reviewing your code. However, it’s important not to overdo it with comments, as too many comments can make the code harder to read and maintain.
PHP Comment Example
//This is One line Comment
echo “Welcome to w3htmlschool.com”
/*This is Bloack comment
My First Progam