If you know PHP at all, you should know echo. Here are a few things you may not know about it.

  • It’s not a function but a language construct
  • Takes multiple arguments separated by a comma
  • Has a short cut <?= (when short tags are on)
  • Has a related function: print()

Since echo is not a function, it does not require parentheses and in fact, some would say don’t use them with echo at all. Also, there are places you could use a function where something like echo can not be used.

The example below gives a parse error when using echo. It doesn’t return a value, for one, and a language construct just doesn’t belong in a spot like that.

if(echo 'this') {
  //parse error
}
 
if(print( 'this' )) {
  //this works
}

You can give echo multiple string separated by commas. The end result will be the same as if you concatenated the strings. Concatenation will be slightly slower but typically not a significant amount. If you use commas, you can not use parentheses or it would also give a parse error.

echo 'a', 'b';   // ab
echo 'a' . 'b';  // ab
echo ('a', 'b'); // parse error