How to print in php: echo and print in php

Today we are going to learn how to print in PHP.




echo in PHP:
The echo() function outputs one or more strings. Return Value: No value is returned.

example:

<?php
echo "Hello world!";
?>


Output:
Hello world!

other example:
<?php
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo"; // foo is foobar
?>


other example: Join two string variables together
<?php
$str1="Hello world!";
$str2="What a nice day!";
echo $str1 . " " . $str2;
?> 


output:
Hello world! What a nice day!

Tip: The echo() function is slightly faster than print().


print() in PHP:
The print() function outputs one or more strings. It always returns 1.

example:

<?php
print "Hello world!";
?>


Output:
Hello world!

Tip: The print() function is slightly slower than echo().



Learn PHP: read and understand these posts:

Learn PHP : PHP variables
How to find PHP version through command prompt in windows?
Learn PHP: Hour 1
Learn PHP: Hour 2

No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!