Related post

How to display output in PHP using echo and print -Zhullyblog




Hello, welcome to zhullyblog. If this is your first time here , please Subscribe to Zhullyblog by Email to get latest tutorial.



PHP Echo and Print 
Echo and print are used to display output in PHP.

PHP Echo statement
Let’s start with echo statement. The echo statement can display anything in the browser such as strings , numbers , variables e.t.c

It works faster than print and can take multiple statement. It can be used with or without parentheses.

Let’s take a quick example. The code below will print Hello world using the echo statement.



<?php
// Display hello world

echo "Hello World!";
?>


And this is the result

PHP echo statement



Example 2


<?php
// Declare variables
$str = "Hello World!";
$num = 23567;

// Displaying variables
echo $str;
echo "<br>";
echo $num;
?>



Result





The PHP print statement
The print is an alternative to echo statement in PHP. You can display an output to the browser same way you display output using echo statement. Print and echo are quite similar just that the print statement only output one string.

Let’s see how a string is displayed using print.


<?php
// Displaying string o
print "Hello World!";
?>



Example 2
Here is an example.


<?php
// Declare variables
$txt = "Hello World!";
$num = 56891;

// Displaying variables
print $txt;
print "<br>";
print $num;
?>




Please share









OTHER TUTORIALS





Latest Tutorials










Comments