In PhP there are two basic ways to get output: echo and print.
echo
- echo is a statement i.e used to display the output. it can be used with parentheses echo or without parentheses echo.
- echo can pass multiple string separated as ( , )
- echo doesn’t return any value
- echo is faster then print
Example
<?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?>
Output
PHP is Fun!
Hello world!
I’m about to learn PHP!
This string was made with multiple parameters.
- Print is also a statement i.e used to display the output. it can be used with parentheses print( ) or without parentheses print.
- using print can doesn’t pass multiple argument.
- print always return 1
- it is slower than echo
Example
<?php print "<h2>PHP is Fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!"; ?>
Output
PHP is Fun!
Hello world!
I’m about to learn PHP!