PHP echo statement & Print statement

PHP echo statement & Print Statements:

Now we learn about PHP output statements.These two statements are essential to get output.
1. PHP echo statement
2. PHP print statement

But here is little bit difference between them.

1. Echo return output more strings.
2. Print return output only one string & print always return 1.

php 
echo "

Welcome to Knowledge idea !!

";
echo "Practice makes a men perfect
";
?>

Above examples shows php echo output with strings.Please keep in mind always use quotes around the text/character.
Secondly we discuss on string and variable usage with PHP echo output statement.
Let’s take example.

php 
$info="Just do it";
$data="Necessary is the";
$text="mother of invention"; 
$Home=array("Florida","London","New York","Japan"); 
echo $info
echo $data $text
echo "My Home at {$Home[1]}";
echo "{$Home[0]} is a beautiful place"; 
?>

As you seen,Above example consist on variable such as $data,$info,$text and other’s. which are working with output statement echo.Keep in mind “$” sign declare the variable.

Print Statements:

Comeback on previous topic print is also used to get output.
Let’s take an example with few strings.

php 
print "

Welcome to Knowledge idea !!

";
print "I Want to earn knowledge about php
";
?>

This following example showing the variable and strings with print statement.

php 
$info="Just do it";
$data="Necessary is the";
$text="mother of invention"; 
$Home=array("Florida","London","New York","Japan"); 
print $info
print $data $text
print "My Home at {$Home[1]}";
print "{$Home[0]} is a beautiful place";  
?>

Both are approximately same output statements.
Practice as yourself !!

Leave a Reply

Your email address will not be published. Required fields are marked *