PHP Programing language

Echo in PHP
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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: