PDA

View Full Version : [PHP] Differenze tra echo e print ce ne sono?


Matrixbob
22-07-2010, 09:45
Devono per forza esserci altrimenti non mi spiego la doppia keyword ....

Torav
22-07-2010, 10:07
Per quanto riguarda il loro uso non c'è nessuna differenza (che io sappia), mentre echo è un pochino migliore dal punto di vista delle performance. Qua (http://www.learnphponline.com/php-basics/php-echo-vs-print) è spiegato un po' meglio

Matrixbob
22-07-2010, 10:17
Riporto dei commenti xkè l'articolo evidenzia la keyword + corta e le prestazioni leggermente superiori di echo.


Hi, i just wanna say that I’ve tested that in this code:
print “Hello World! “,”Again Hello World! “;
using the sign comma(,) in print does not work.
Using “echo” you can print multiple values but the same is not possible with “Print”.
The print command returns a 1 if successful, the extra return command is what makes the speed difference.

Test1]
php -d implicit_flush=off -r ‘$s=microtime(true); for($i=0;$i<100000;$i++) echo "omgwtf","bbq","\n"; echo microtime(true)-$s; flush();' | fgrep -v "omg"
0.069

Test2]
php -d implicit_flush=off -r '$s=microtime(true); for($i=0;$i<100000;$i++) echo "omgwtf"."bbq"."\n"; echo microtime(true)-$s; flush();' | fgrep -v "omg"
0.074

if we use print(“hello”+5);
then output will be 5 only bcoz it take only 1 argument.

But with echo we can do like this:-
$a=5;
echo “hello”.$a;

output will be hello5.

2) "Use single-quotes for strings."
3) "Use echo to print."
4) "Don't use concatenation with echo."