What is the difference between echo and print

PHP echo and print Statement

echo and print is more or less the same. They are both used to output data to the screen.

PHP echo and print Statement

echo and print is more or less the same. They are both used to output data to the screen.

PHP echo and print Statement

The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

Difference between echo and print

1. echo  2. print

echo

– echo is a statement, which is used to display the output. – echo can be used with or without parentheses. – echo does not return any value. – We can pass multiple strings separated by comma (,) in echo. – echo is faster than a print statement.

print

– print is also a statement, used as an alternative to echo at many times to display the output. – print can be used with or without parentheses. – print always returns an integer value, which is 1. – Using print, we cannot pass multiple arguments. – print is slower than the echo statement.

echo Example

Example // Displaying HTML code echo "<h4>This is a simple heading.</h4>"; echo "<h4 style='color: red;'>This is heading with style.</h4>"; Output This is a simple heading. This is heading with style.

print  Example

Example 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! Display Strings of Text