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@paramand@returntags.
<?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?
// comment# comment/* comment */<!-- comment -->
Show answer
Answer: <!-- comment -->