This is a continuation of the series related to the basics of PHP. Let's look at the code commenting syntax and use cases of PHP commenting. PHP Code comments usually use inside PHP open and close tags. These comments will not return along with the rendered HTML code from the server. Code commenting helps add notes to the code for later use.
PHP Code Comment Example
<?php
// commented code
$a = 10; #$a is a number
$b = 20; #b is another number
/*
$c gives sum of $a and $b
this is a multiple line comment
one more line of comment
*/
$c = $a+$b;
echo $c;
In the example above we used 3 different types of code commenting inside PHP.
// commented code
This particular line is a inline commenting example. There is another 2 examples of inline code commenting as shown below.
$a = 10; #$a is a number
$b = 20; #b is another number
In both these cases there is a use of hash(#) before the line to mark it as a commented code.
PHP Multi line comment
/*
$c gives sum of $a and $b
this is a multiple line comment
one more line of comment
*/
Above syntax is usually uses to represent multi line code comments.
The commented code starts with /* and end ends with */
Developers uses code commenting for multiple use cases. Most of the time code commenting helps developers to understand the code. This is even helps the same developer to understand it later.