Single Line Comment In PHP
Last Updated : Jan 1, 2023
IN - PHP
In this tutorial we will show you the solution of single line comment in PHP, comments means those are not display on webpage and also it not affects our program.
In every language has comment because it must and useful when we defining program we can use this to notes part of line code what is the purpose we written.
So we can understand later when we open program and it is visible only when we open this program otherwise we can’t recall.
For comments we need to use some charaters before instruction line of text in php.
Step By Step Guide On Single Line Comment In PHP :-
Here we will see about single line comments in php. We can use # (hash) or // (double-slash) for comment single line of text.
In php comments can be used to describe any line of code so that other developer can understand the code easily.
It is also be used to hide any code. Php supports single line and multi line comments also.
<?php #echo "hello"; // echo "hello"; #echo used for print string on display echo "hello"; ?>
- A php script can be placed anywhere in the document. A php script starts with <?php and end with ?>.
- The default file extension for php files is “.php” and php statements end with ‘;’ semicolon.
- As we know # (hash) used for single line comment so the ‘echo "hello";’ will not print on display because we used # at before that line.
- Same as next line of ‘echo "hello";’ also will not be printed on display because we used ‘//’ so it also commented. Those comments line of sentence displays on green color in editor when we comments.
- Third line of comment looks like instruction for below code so after long time when we open this same program we can easily recalls it like, we writes this code for this purpose.
- Last line will print on display without doubt because we are not used any comment character before that line. So the output will have single word of string ‘hello’ only.
- We can use this when we need to avoid some part of code from execution that time also we can comment those codes.
In conclusion we are able to know how to covert stdclass object to array using php.
When work with php we need to create and process php files at server location and then we need to start the server before execute the program.
When we executing this program on browser it will prints one string ‘hello’ once only on webpage.
In some places we need to give instruction of paragraph about code so there we have to give comment character for each line of texts, it so complicated.
That’s way they provide multi line comments also in php by use that we can easily comments more number of line texts.
I hope this tutorial on single line comment in PHP helps you and the steps and method mentioned above are easy to follow and implement.