PHP comments are “notes” that the programmer adds to the code for convenience. These are “notes”, simple text that is neither processed nor printed on video: in practice, these are internal references that can only be read by the developer who works on the source code of the script.
For example, it may be useful to write above a certain function what its task is or how it should be used in the application context, or why a certain sequence of steps necessary to achieve a certain result.
Comments are critical (and should not be overlooked) for a number of reasons:
- because they simplify interventions to the code carried out at a time after its creation (after a long time, in fact, certain logical steps may appear less clear);
- because they facilitate the task of other people called to work on our code.
How To Write A Single-line Comment In PHP
Writing a comment inside the PHP code is very simple … just start a line with // or with #. Anything placed on the right will not be processed by PHP and therefore will have no effect during processing. Let’s take an example:
<?php //Use echo. echo "Hello!"; #use print! print "hello!"; ?>
or
<?php echo "Hello World"; //Use echo. print "HELLO WORLD"; #Use print. ?>
How To Write A Multiline Comment In Php
we want to write comments on multiple lines we can use this syntax:
/* This is Multiline Comments... we can use here some line... */ echo "Hello PHP!";
As you may have noticed, anything between / * and * / is considered comment, regardless of whether it occupies one or more lines.