Previous | Home | Next |
Echo Statement in PHP
The echo statement can be used with or without parentheses: echo or echo(). It is used to output data to the screen. It has no return value. Actually echo() is not a function, it is a language construct therefore you can use it without parentheses.
Example:
<html> <body> <?php $txt1 = "Apple, Mango, Banana, Grapes, Orange"; $x = 3; $y = 2; echo "Fruits are: " . $txt1 . ".<br>"; echo "Total fruits are: "; echo $x + $y; ?> </body> </html>
Output:
Fruits are: Apple, Mango, Banana, Grapes, Orange. Total fruits are: 5
Print Statement in PHP
The print statement can be used with or without parentheses: print or print(). It is used to display a string. It has a return value of 1 so it can be used in expressions. Print() is not actually a real function, it is a language construct like echo.
Example:
<html> <body> <?php $txt1 = "Apple, Mango, Banana, Grapes, Orange"; $x = 3; $y = 2; print "Fruits are: " . $txt1 . ".<br>"; print "Total fruits are: "; print $x + $y; ?> </body> </html>
output:
Fruits are: Apple, Mango, Banana, Grapes, Orange. Total fruits are: 5
Previous | Home | Next |