Advertisement

Google Ad Slot: content-top

PHP Comments


Comments in PHP


PHP comments can be used to describe any line of code so that other developer can understand the code easily. It can also be used to hide any code. Comments in PHP are lines of code ignored by the PHP engine during execution.


Types of PHP Comments

1. Single-Line Comments


Single-line comments are used to comment out one line or part of a line of code. There are two ways to create single-line comments:

Using // (C++ style single line comment)
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
echo "Hello, PHP!"; // This comment explains the code
?>
</body>
</html>

Try it yourself
Using # (Unix Shell style single line comment)
<!DOCTYPE html>
<html>
<body>
<?php
# This is another way to write a single-line comment
echo "PHP is great!";
?>
</body>
</html>

Try it yourself

2. Multi-Line Comments


Multi-line comments are used to comment out multiple lines of code. They start with /* and end with */.

Example
<!DOCTYPE html>
<html>
<body>
<?php
/*
This is a multi-line comment.
It can span multiple lines.
Useful for explaining complex code or temporarily disabling large code blocks.
*/
echo "This line of code is executed.";
?>
</body>
</html>

Try it yourself