PHP Comments


With PHP comments can be used to explain the code and make it more readable. Comments can also be used to prevent execution, when testing alternative code. In PHP we can use C, C++ style comments. There are two types of Comments :

1. Single Line Comment :

There are two ways to use single line comments in PHP.

a. With ouble forward slash ( // ) :

A single-line begins with double forward slash ( // ). Any text after  // will be ignored by php. For example :
<?php

  $num = 1000;
  $float = 25.80;
  $str = "Hello world";

  // echo $num . "<br/>";
  // echo $float . "<br/>";
  // echo $str . "<br/>";

?>

b. With Hash/Pond Sign  ( # ) :

Any text after # sign will be ignored by php. For example :
<?php

  $num = 1000;
  $float = 25.80;
  $str = "Hello world";

  # echo $num . "<br/>";
  # echo $float . "<br/>";
  # echo $str . "<br/>";

?>

2. Multiline comment :

A multi-line comment begins with forward slash and asterisk ( /* ), and end with the reverse asterisk and forward slash ( */ ). Any text between /* and */ will be ignored by php. For Example :
<?php

  $num = 1000;
  $float = 25.80;
  $str = "Hello world";

  /* echo $num . "<br/>";
     echo $float . "<br/>";
     echo $str . "<br/>";
  */

?>

Next Topic :