unknown os platform
Free Beginner PHP Tutorials - Comments | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - Comments


Free
2016/08/26 / Science and Tutorials

A comment in PHP code is a line that is not read as part of the program See example:-





using comments in php


Comments in PHP are purposely used to explain a particular code snippet. Besides, it gives web developer or other others who may view the code a clue about the functionality of a particular function or code snippet. PHP comments are shown using two special characters and all text that appears between the start and the end of the comment will be not be executed.

Note that, PHP's comments are not displayed to your visitors web page. The only way to view comments in PHP is to open the PHP file in an editor for editing. This makes PHP comments useful to PHP programmers only.

There are two types of comments in PHP.
1.Single-line comment
2.Multiple-line comment 

Let us see examples of PHP comments

Example 1

Single-line comment (// or #)


<?PHP
        //The code to output the sum of two numbers
       # working           $num1="10";
        echo "The Sum of two numbers is ".$sum;
          $num2="10";           $sum=$num1+$num2;
?>

The above code will output
The Sum of two numbers is 20.

 The single line comment (// or # )tells the interpreter to ignore everything that occurs on that line to the right of the comment.
The words to the right of the comment are not executed.

Example 2

Multi-line comment (/* */)


<?PHP         /* The code to output the sum of two numbers              create two variables each initialized with a value of ten              number 1 has a value of 1             and number two has a value of 10        */     $num1="10";     $num2="10";     $sum=$num1+$num2;     echo "The Sum of two numbers is ".$sum; ?>

The above code will output
The Sum of two numbers is 20.

The multi-line comment begins with '/*' and ends with '*/'. It is used to comment large blocks of code or notes. 
The words or sentences that lie inside /* and */ are not executed.

Application of comments
Most programmers write very complex code snippets, and it becomes difficult for the system maintainers and analyst to understand the flow and the structure of the code.  Comments can be used in such a case to explain the code at every single step made by the developer to make it simple for the system maintainers.

Note, use comments in your program for a better understanding of the code snippet.












You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment