Echo and Print Statements in PHP



PHP echo Statement


Echo statement can produce one or more strings. In general terms, the echo statement browser can be displayed which can display anything, such as the results of string, numbers, variable value, expression etc.

Since echo is a language, there is actually no function (such as statement), you can use it without brackets eg. Echo or resonance () However, if you want to pass more than one parameter to resonate, the parameters should not be added within the brackets.

Example - 

<?php
// Displaying string of text
echo "Hello World!";
?>

Output -

Hello World!

Display HTML Code


Example - 

<?php
// Displaying HTML code
echo "<h4>This is a simple heading.</h4>";
echo "<h4 style='color: red;'>This is heading with style.</h4>"
?>

Output -

This is a simple heading.


This is heading with style.



Display Variables


Example - 

<?php
// Defining variables
$txt = "Hello World!";
$num = 123456789;
$colors = array("Red", "Green", "Blue");

// Displaying variables
echo $txt;
echo "<br>";
echo $num;
echo "<br>";
echo $colors[0];
?>

output-

Hello World! 
123456789 
Red
Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment