Skip to content

PHP Tutorial PHP Syntax and Output

PHP Comments

Lesson 15 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

A comment is a note for humans. PHP skips it completely. Comments help you remember why you wrote something, and they help the next person who reads your code.

Single-line comments

Use // or #. Everything after it on that line is ignored.

index.php
PHP
<?php
// This is a comment
echo "Hello"; // A comment after code

# This style works too, but // is more common
echo " World";
Output
OUTPUT
Hello World

Multi-line comments

Start with / and end with /.

index.php
PHP
<?php
/*
  This comment
  runs over several lines.
*/
echo "Done";
Output
OUTPUT
Done

DocBlocks

A DocBlock is a special multi-line comment that starts with /**. Editors read it to show help for a function.

index.php
PHP
<?php
/**
 * Adds two numbers.
 *
 * @param int $a First number
 * @param int $b Second number
 * @return int
 */
function add(int $a, int $b): int
{
    return $a + $b;
}

echo add(2, 3);
Output
OUTPUT
5

Turn code off with a comment

Comments are also a quick way to disable a line while you test.

index.php
PHP
<?php
echo "One\n";
// echo "Two\n";
echo "Three\n";
Output
OUTPUT
One
Three

What makes a good comment

Explain the why, not the what. The code already says what it does.

index.php
PHP
// Bad: says what the code already says
$count = $count + 1; // add one to count

// Good: says why
$count = $count + 1; // the header row is not part of the data
warning
Do not leave old code commented out
A file full of commented-out code gets confusing fast. Delete what you no longer need. Version control (Git) keeps the history for you.