Php Comments

Developers use comments to describe the details of the code. In PHP there is three-way to describe the comments.

Shell Method

this method is used to single-line comment and it is used through # to comment the details.


<?php
# describe about code details
?>

Example:- Suppose, You created user_greetings function in the user file.


<?php

# user file

function user_greetings($name){

	return 'Hello '.$name;
}
echo user_greetings('John');
?>
Output:- Hello John

Try it Yourself

Single-line Comment

It is basically used for single-line comment and it works the same as the shell method. this method is copied from the c language.

Syntax:-


<?php
 // describe about code details
?>

Example:- Suppose, You created user_full_name function in the user file.


<?php
// get user full name function

function user_full_name($first_name,$last_name){

	return $first_name.' '.$last_name;
}

echo user_full_name('John','Taylor');
?>
Output:- John Taylor

Try it Yourself

Multi-line Comment

this method is used to comments for multiple lines. this method is copied from the c++ language.

Syntax:-


<?php
 /* 
describe 
about 
code details
*/
?>

Example:- Suppose, You created sum of nunbers in the user file and you defined multi-line comments for number1 and number2 .


<?php
/*
$number1=10
$number2=20;
*/
$number3=30;
$number4=40;

$sum_of_numbers=$number3+$number4;

echo $sum_of_numbers;
?>
Output:- 70

Try it Yourself