Thursday 11 March 2021

php: echo: print the data to console

‘echo’ function is used to print data to console.

 

Syntax

echo data_to_print;

 

Whatever follows echo statement is printed to the console by php.

 

Example

echo "Hello World";

 

If you want to concatenate information from multiple places use . (dot) operator.

 

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

 

echo_demo.php

#!/usr/bin/php

<?php 

	echo "Hello World";
	
	$age = 23;
	$name = "Krishna";

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

 

Output

$./echo_demo.php 

Hello WorldHello Mr.Krishna, you are 23 years old

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment