All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Single Line Comment In PHP

Last Updated : Mar 11, 2024

Single Line Comment 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";
?>
  1. A php script can be placed anywhere in the document. A php script starts with <?php and end with ?>.
  2. The default file extension for php files is “.php” and php statements end with ‘;’ semicolon.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. We can use this when we need to avoid some part of code from execution that time also we can comment those codes.

Conclusion :-

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.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪