PHP Comments

PHP comments are used to describe the purpose of code or provide additional information about the code. Comments are ignored by the PHP interpreter during execution.

In PHP, there are two types of comments:

Types of Comments in PHP

1. Single-line Comments

Single-line comments are used to comment only one line of code. They can be created using either of the following syntax:

Example


<?php
// This is a single-line comment
echo "Hello World!"; # This is another single-line comment
?>
            

Output

Hello World!

2. Multi-line Comments

Multi-line comments are used to comment multiple lines of code. They are created using /* ... */ syntax.

Example


<?php
/*
This is a multi-line comment.
It can span multiple lines.
*/
echo "Welcome to PHP Comments!";
?>
            

Output

Welcome to PHP Comments!

Why Use Comments?

Comments are essential for making your code easier to understand. Here are some reasons to use comments in PHP: