1.

List the differences between Echo and Print in PHP.

Answer»

The functions of echo and print are nearly identical. Both are used to display info on the screen.

The differences are MINOR

  • Echo returns nothing, WHEREAS print returns 1 and can be used in expressions.
  • While echo can take many parameters, print only takes one.
  • Because echo does not RETURN a value, it is faster than print.

Example:

<!DOCTYPE html><html><body><?phpprint "PHP is fun!<br>";echo "PHP is fun.<br>";echo "PHP ", "is ", "fun.";?> </body></html>

Output:

PHP is fun!PHP is fun.PHP is fun.

The above example SHOWS that echo can take many parameters whereas print cannot. We obtain a syntax error if we try to pass multiple parameters into print. 



Discussion

No Comment Found