PHP Tutorial · PHP Basics · Lesson 4 of 38

PHP Comments

Single-line, multi-line and PHPDoc comments.

Comment styles

  • // and # start a single-line comment.
  • /* ... */ spans multiple lines.
  • /** ... */ is a PHPDoc block — IDEs and tools read the @param and @return tags.
Example 1Try it yourself
<?php
// A single-line comment
# Also a single-line comment
/*
  A multi-line comment
*/

/**
 * Add VAT to a net price.
 *
 * @param float $net  price without tax
 * @param float $rate e.g. 0.2 for 20%
 * @return float
 */
function withVat(float $net, float $rate = 0.2): float
{
    return $net * (1 + $rate);
}

echo withVat(100); // 120

Output

120

Test yourself

Which of these is NOT a PHP comment?

  1. // comment
  2. # comment
  3. /* comment */
  4. <!-- comment -->
Show answer

Answer: <!-- comment -->