Download kotlin Programming APP on PlayStore
Download Website SEO Lessons APP on PlayStore
Comments in PHP are not executed by the PHP interpreter, but are skipped by it instead. They serve as programmers to make your code easier to understand. You can, as the name says, comment on your program code, that is, explain what functions individual sections of the program have.
Defining comments in PHP
To insert a comment in a PHP script, you can either use two slashes //, /* comment here */ or a rhombus #. If one of these two characters appears in your program code, the rest of the contents of the line will be skipped and the PHP interpreter will move to the next line.
<? Php echo "Hello world! <br>"; // This is a comment # Another comment - output of the text echo "As you can see, the comments are not visible on the output."; ?>
Everything that is double slash or after the diamond is ignored. The newline then terminates the comment and the code in the next line is executed again.
Multi-line comments in php
Sometimes it makes sense to have a comment over several lines, for example, if you want to comment out a program section.
Such a comment starts with / * and ends with * / :
<? Php / * The first line of the comment Second line of the comment The last line of the comment * / echo "Hello World, As you can see, only this text will be shown, the comments in front of it are not visible."; ?>
What and how should one comment in php?
Comments allow you as a programmer to comment on the functionality of your scripts. Basically, you are not obligated to use them, but they can help you enormously to make your code clearer and easier to understand.
You should always tend to comment on what your script does, rather than how it does it. So you tend to comment on the functionality so that when you re-study the program code, it quickly becomes clear what exactly individual sections of the code are doing. Just when you define your own functions , you should briefly comment on the function at the beginning of the function.