Thursday 11 March 2021

Php: comments: Documenting the code

Comments are used to document your code. Comments start with // and any information after // is treated as comment and not processed by php.

 

Syntax

// This is an example of comment

 

Example

// Following statement prints data to console

echo "Hello World";

        

// Following statements define variable

$age = 23;

$name = "Krishna";

 

comments_demo.php

#!/usr/bin/php

<?php 

	// Following statement prints data to console
	echo "Hello World\n";
	
	// Following statements define variable
	$age = 23;
	$name = "Krishna";

	echo "Hello Mr." . $name . ", you are " . $age . " years old";
?>

 

Output

$./comment_demo.php 

Hello World
Hello Mr.Krishna, you are 23 years old

Php support two types of comments.

a.   Single line comments: Starts with // or # symbol

b.   Multiline comments: Starts with /* and ends with */.

 

comments_demo_1.php

#!/usr/bin/php

<?php 

	// This is single line comment
	# This is also single line comment

	/*
		This 
			is 
				a 
					multiline comment
	*/

?>




 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment