PHP Comments

PHP

PHP Comments play a very important role in this language, to know about this 1st we know what is comments.

Comments:

The part of the source code in a programming file, which is not executable by a compiler called Comments.

Basically, comments are used for:

  • To make the reader understand by describing the action of a statement, just like
    $a += 07; // Increment $a by 07
  • Another good way is to temporarily hide the statement of the code that is giving the errors, like
    // echo “Value equals $x”;

In PHP there are two common ways to add comments in the PHP programming file.

SINGLE LINE COMMENT:-

A single line or a statement of code can be turned into a comment by
preceding it with a pair of forwarding slashes.

Syntax

<?php

// This is a single-line comment

?>

Example

<!DOCTYPE html>
<html>

<head>

<title>PHP Single line Comment</title>

</head>

<body>

<?php

$x = 07;
// Display variables value
echo $x;

?>

</body>
</html>

MULTI-LINE COMMENT:-

A set of statements in a programming file that you want to hide from the compiler by using the /* and */ pairs of characters to open and close comments anywhere inside the file.

Syntax

<?php

/* This is a section
of multi-line comments
which will not be
interpreted */

?>

Example

<!DOCTYPE html>
<html>

<head>
<title>PHP Multi-line Comment</title>
</head>

<body>

<?php

$x = 07;

/*After assigning the
digit 7 to variable “x” now
it will be displayed on the
web page*/

echo $x;

?>

</body>
</html>

 

Click to know, What is PHP Variables.

Leave a Reply

Your email address will not be published.