Comment in PHP

Find this useful? Support us: Star on GitHub 6
Category: Other | Language: PHP

In PHP, there are two ways to add comments.

Single-line comments: Use double forward slashes (//) to add a single-line comment.

Example:

// This is a single-line comment in PHP

Multi-line comments: Use forward slash and an asterisk (/*) to start the comment and an asterisk and a forward slash (*/) to end the comment. This type of comment can span multiple lines.

Example:

/*
This is a
multi-line
comment in PHP
*/

Comments are used to add notes and explanations to your code, which can help you and other developers understand and maintain the code. It’s a best practice to add comments to your code to make it more readable and understandable.