Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From: <a href="http://web.archive.org/web/20090221144611/http://faqts.com/knowledge_base/view.phtml/aid/1/fid/40" rel="noreferrer">http://web.archive.org/web/20090221144611/http://faqts.com/knowledge_base/view.phtml/aid/1/fid/40</a></p> <ol> <li><p>Speed. There is a difference between the two, but speed-wise it should be irrelevant which one you use. echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty. </p></li> <li><p>Expression. <code>print()</code> behaves like a function in that you can do: <code>$ret = print "Hello World"</code>; And <code>$ret</code> will be <code>1</code>. That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:</p></li> </ol> <pre class="lang-php prettyprint-override"><code>$b ? print "true" : print "false"; </code></pre> <p>print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precedence list though. Only "," AND, OR and XOR are lower.</p> <ol start="3"> <li>Parameter(s). The grammar is: <code>echo expression [, expression[, expression] ... ]</code> But <code>echo ( expression, expression )</code> is not valid. This would be valid: <code>echo ("howdy"),("partner")</code>; the same as: <code>echo "howdy","partner"</code>; (Putting the brackets in that simple example serves no purpose since there is no operator precedence issue with a single term like that.)</li> </ol> <p>So, echo without parentheses can take multiple parameters, which get concatenated:</p> <pre><code> echo "and a ", 1, 2, 3; // comma-separated without parentheses echo ("and a 123"); // just one parameter with parentheses </code></pre> <p><code>print()</code> can only take one parameter:</p> <pre><code> print ("and a 123"); print "and a 123"; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload