PHP echo and print

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.

You can also search for these topics, php echo and print statements, php echo and print example, php echo and print difference, difference between echo and print in php.

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
echo "<h3>PHP is Fun!</h3>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.<br />";
$txt1 = "Learn PHP";
$txt2 = "simmanchith.com";
$x = 5;
$y = 4;
echo "<h3>" . $txt1 . "</h3>";
echo "Study PHP at " . $txt2 . "<br />";
echo $x + $y;
?>

Output :-

PHP is Fun!

This string was made with multiple parameters.

Learn PHP

Study PHP at simmanchith.com
9



You can also search for these topics, php echo statement, php echo statement example, php echo html tags, php echo variable in html, php echo display text, php echo display text example, php echo display variable, php echo display variable example.

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
print "<h3>PHP is Fun!</h3>";
print "Hello World!";
$txt1 = "Learn PHP";
$txt2 = "simmanchith.com";
$x = 5;
$y = 4;
print "<h3>" . $txt1 . "</h3>";
print "Study PHP at " . $txt2 . "<br />";
print $x + $y;
?>

Output :-

PHP is Fun!

Hello World!

Learn PHP

Study PHP at simmanchith.com
9



You can also search for these topics, php print statement, php print timestamp, php print function, php print datetime, php print display text, php print display variable, php print display text example, php print display variable example.