PHP echo and print
There are two primary methods for generating output in PHP: echo and print.
The functions of echo and print are nearly identical. They're both utilized to display info on the screen.
Differences are small: echo does not have a return value whereas printing is 1 and can be used in terms. While print may accept a single argument, echo can accept many parameters (though such uses are rare).]
The echo is a fraction of a second quicker than print.
The PHP echo Statement
The declaration echo with or without parentheses: echo or echo() can be used.
Display Text and Variable
The echo command is used in the following example to output text and variable.
(Please keep in mind that the content may include HTML markup).
Example :- The following example demonstrates how to use the echo statement to produce text and variables:
PHP is Fun!";
echo "This ", "string ", "was ", "made ", "with multiple parameters.
";
$txt1 = "Learn PHP";
$txt2 = "simmanchith.com";
$x = 5;
$y = 4;
echo "" . $txt1 . "
";
echo "Study PHP at " . $txt2 . "
";
echo $x + $y;
?>
Output :-
PHP is Fun!
This string was made with multiple parameters.
Learn PHP
Study PHP at simmanchith.com9
Related Links
The PHP print Statement
The declaration print with or without parentheses: print or print() can be used.
Display Text and Variables
The print command is used in the following example to print text and variables.
(Please keep in mind that the content may include HTML markup.
Example :- The following example demonstrates how to use the print statement to produce text and variables:
PHP is Fun!";
print "Hello World!";
$txt1 = "Learn PHP";
$txt2 = "simmanchith.com";
$x = 5;
$y = 4;
print "" . $txt1 . "
";
print "Study PHP at " . $txt2 . "
";
print $x + $y;
?>
Output :-
PHP is Fun!
Hello World!
Learn PHP
Study PHP at simmanchith.com9
Related Links