Put comments in PHP

Put comments at PHP as in any programming language, it is quite useful to write implementation details of our code in addition to other references necessary to understand the code written by us.

The most natural way of writing comments in PHP has two basic forms, long comments in which we can introduce a block with several explanatory sentences or short comments where the information is explained in a simple sentence.

In order to explain the generation of comments we are going to create a program that manipulates numbers in PHP and we will introduce different comments in it that make said code explanatory.

To write long comments, /* is used to start writing and */ to end writing the comment as follows:

/*
  This is a long comment
  Here we describe that a subtraction is made of only integer values ​​contained in the variables
  which has been stated below
*/

  $i="46875"
  $j="5743"

To write short comments, use // and then write the comment in PHP everything in a single line until the line break as follows:

// Here you put a single line comment
echo "Subtraction... ";
echo $i-$j;

// This is a comment behind a statement
echo "<br>";

The two types of comments can be combined within the same code, that is, they are not exclusive. The most normal thing is to find long comments at the beginning of the program or a function or a class, while we write short comments in front of code statements that we want to explain.

Put comments at PHP’s basic purpose is to document our code. It is a good programming practice to detail well the use of our code.