How to write comments in PHP
Topic: PHP / MySQLPrev|Next
Answer: Use the Syntax "// text"
and "/* text */"
Comments are usually written within the block of PHP code to explain the functionality of the code. It will help you and others in the future to understand what you were trying to do with the PHP code. Comments are not displayed in the output, they are ignored by the PHP engine.
Single Line Comments
PHP single line comment begins with //
, See the example below:
Example
Try this code »<?php
echo "Hello World!"; // Output "Hello World!"
?>
Multi-line Comments
PHP multi-line line comment begins with /*
, and ends with */
.
Example
Try this code »<?php
/* The following line of code
will output the "Hello World!" message */
echo "Hello World!";
?>
Related FAQ
Here are some more FAQ related to this topic: