PHP Comments

PHP First Program Previous Next PHP Variables


Comments are inserted in PHP to explain the code.

A Comments in PHP code is a line that is not executed as a part of the program.

This is specially useful when there are too many lines of code and the programmer can insert the comments not only to divide the page into logical sections to increase the readability of code.

But also to give information about the author of the code,the date on which the code was last edited etc.

There are two types of comments in PHP.

  1. Single Line Comments
  2. Multi Line Comments

PHP Single Line Comments


Single line comments in Php are start with two forward slashes( // ).

All text after // will be ignored by PHP.

e.g // This is single line comments.

Filename: single-line-comments.php


Code
<?php
// This is single line comments
echo "Hello World"; // Hello World
$a=10;$b=20;
echo $a+$b; // 30
?>

Running Step.


Type Url - https://localhost/php/single-line-comments.php

PHP Multi Line Comments


The multi line comments can be used to comments out large blocks of code.

Multi line comments in Php are begines with /* and ends with */.

All text between /* */ will be ignored by Php.

e.g

/* This is Multi line comments 1

Multi line comments 2 */

Filename: php / multiline-comments.php


Code
<?php
/*  This is Multi line comments 1
    Multi line comments 2 */
?>

Running Step.


Type Url - https://localhost/php/multiline-comments.php

Well there are several pattern to create comments in PHP given below.

Filename: php / more-comments.php


Code
<?php
# Comments Style 1

echo "Hello World"; # Hello World

$a=10;$b=20;
echo $a+$b; # 30
?>

<?php
/* Comments Style 2 */

echo "Hello World"; /* Hello World */

$a=10;$b=20;
echo $a+$b; /* 30 */
?gt;

<?php
//=========================== Comments Style 3 =========================== //

echo "Hello World"; //==== Hello World ===//

$a=10;$b=20;
echo $a+$b; //==== 30 ====//
?>

<?php
//----------------------- Comments Style 4 -----------------------//

echo "Hello World"; //---- Hello World ----//

$a=10;$b=20;
echo $a+$b; //---- 30 ----//
?>

<?php
/**
* This is multi line 
* Comments Style 5
* add more row for comments
*/
?>

Running Step.


Type Url - https://localhost/php/more-comments.php


Tags: PHP


Was this helpful ?

Related Code


Popular Code

Latest Code