Last Updated on December 30, 2020 by Roshan Parihar
In this tutorial, learn how to write comment in PHP including single line and multiline. The short answer is: use the symbol //
for single line and /* */
for multiline comments.
How to Write Comment in PHP
Using comments in your PHP coding is the best practice for PHP coders and developers to create applications using PHP. It helps you easily understand the purpose of each line of code in just a single view.
So, let’s find out how you can create and add comments using PHP.
PHP Single Line Comment
There two symbols #
or //
you have to use any one of them at the start of the line of code to make it commented. It’s the simplest way of commenting out a line of code or put a comments at the end of each line to describe the purpose of the line.
1 2 3 4 5 |
//This is a first comment echo "Welcome to TutorialDeep!"; echo "<br>"; #This is a second comment echo "How are you today?"; //This is the comment |
Output
How are you today?
PHP Multi-Line Comment
You can use PHP multiline comments system to comment out more than one line. Use the start symbol /*
to start the comment and the end symbol *\
to the end of the comment to create a multiline comment.
1 2 3 |
/*This is the example to show the multiline comment system in PHP. The example does not display the comment in the output.*/ echo "Welcome to Tutorialdeep!"; |
Output
The above example contains the multiline comment that is not visible in the output. You can add as many lines in the multiline comment starting /*
and ending *\
tag.
You must also read.