PHP Comments

Essential PHP comment operations

2 min read |239 words
May 30, 2026

Comments

In PHP, comments are used to explain code and make it more readable. There are three types of comments in PHP:

  1. Single-line comments: These comments start with // or # and continue until the end of the line.
// This is a single-line comment using double slashes
# This is a single-line comment using a hash
  1. Multi-line comments: These comments start with /* and end with */. They can span multiple lines.
/*
This is a multi-line comment.
It can span multiple lines.
*/
  1. Doc comments: These comments start with /** and end with */. They are used for documentation purposes and can be parsed by tools like PHPDoc.
/**
 * This is a doc comment.
 * It can be used to generate documentation.
 *
 * @param string $name The name of the person
 * @return string A greeting message
 */
function greet($name) {
    return "Hello, " . $name . "!";
}

Conclusion

Using comments effectively can help improve the readability and maintainability of your PHP code. It is a good practice to include comments that explain the purpose of your code, especially for complex logic or when working in a team. Always strive to write clear and concise comments that add value to your code.