How to add comments in PHP?

By | July 28, 2022

A PHP comment is a line of code that is not run as part of the program. It’s sole function is to be readable by someone who is scanning the code. 

Comments may be employed for

  1.  Making your code clear to others.
  2. Remind yourself of what you accomplished, Most programmers have encountered the challenge of having to rediscover what they accomplished when returning to their own work after a year or two. 
  3. Comments might serve as a reminder of your thoughts when writing the code.

Example for adding comments in PHP code.

  1. Syntax for single line comment:
<!DOCTYPE html>
<html>
<body>

<?php
// This is a single-line comment

# This is also a single-line comment
?>

</body>
</html>

2. Syntax for multiple line comment:

<!DOCTYPE html>
<html>
<body>

<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>

</body>
</html>