This tutorials tells you, how to use PHP comments in your php code. This part of PHP lets the developer write human-readable lines. It is an optional but essential part.

PHP Comments :

PHP Comments help the developer to explain steps and way of reasoning throughout the program, it enabling the easier maintenance.

PHP comments Single Line:

<?php

# This is one way to put it
// Hide all your lines here and no user one will see.
echo "This is the only visible text in this code";
?>

The output is as follow

This is the only visible text in this code

PHP multi Comments line :

<?php

/* A multiline Comment lets you add the following
features and information.
Author: Developer name
Objective: How to add Multiline
language: PHP
*/
print "Only this phrase is visible";
?>

Output:

Only this phrase is visible

If you are familiar with the C programming language, you must have come across this style of commenting. It provides algorithms and pseudocode used in finding solutions.

PHP Whitespaces :

The rules of PHP are lenient on whitespaces. This feature is significant in web design in achieving minimalism on the front end. It is also vital as far as coding is concerned.

It includes things like spaces, carriage returns, tabs, and others which leave blanks. PHP is insensitive to spaces; whether you leave one or ten or a thousand steps, the parser ignores them. For instance, find the fault in the code below:

<?php
echo "Here is how to calculate in PHP";?></br>
<?php
$lions =
21;
$zebras
= 20;

$animals = $lions      +             $zebras;
echo "The number of animals is ",

$animals,", there are 21 lions and 20 zebras";?>

The output is as follows

Here is how to calculate in PHP
The number of animals is 41 , there are 21 lions and 20 zebras

Notice the many spaces. Did you find the mistakes? Well compare that with the following piece of code.

<?php echo "Here is how to calculate in PHP";?></br>
<?php $lions=21;$zebras=20;$animals=$lions+$zebras;echo "The number of animals is ",
$animals," , there are 21 lions and 20 zebras";
?>

The two sets of code are similar and give the following output.

Here is how to calculate in PHP
The number of animals is 41 , there are 21 lions and 20 zebras

There is nothing wrong with any of the code sets above. However, appropriate usage of whitespaces is for enhancement of readability.

PHP Case Sensitivity :

PHP is case sensitive. This is the part of rules of PHP that describes the definition of variables.
In the following code, the use of the same word for a variable but different cases will be interpreted by the parser as different words.

<?php
$Lions=21;
$lIons=22;
$liOns=23;
$lioNs=24;
$lionS=24;
echo "Lions are $Lions, lIons are $lIons, liOns are $liOns, lioNs are $lioNs, and lionS are $lionS";

?>

The output is as follows:

Lions are 21, lIons are 22, liOns are 23, lioNs are 24, and lionS are 24

PHP is a really powerful language that can be used to create dynamic systems. As we saw earlier, big companies have adopted it and used it to great lengths. You can learn the trade too, only of you follow the rules of PHP carefully and practice often.

Happy Learning 🙂