<?php print "Hello World! <br />"; echo "Hello World! <br />"; // The above outputs the text "Hello World!" on two separate lines. // Notice they are identical in output!
print ("Hello World! <br />"); echo ("Hello World! <br />"); // The above are just the same, with parenthesis. // Notice both can act like functions, but note they actually aren't. ?>
In all actuality, Echo and Print differ based on how they are structured. Print returns a value much like a normal function would. But despite common belief, Print is not a function, as we can see by the fact that it doesn’t require parenthesis to work (Not to be confused with Printf). Print and Echo are actually both called language constructs, although this isn’t to say that we can’t make Print act like a function.
PHP Echo Vs Print: Which Is Faster?
Echo is faster than print.
Print can be used as part of complex constructs, such as ($b) ? print “True” : print “False”; // or echo ($b ? “true” : “false”); Also, if you want to use error output (@print”Test”;) Print is easy because almost every language use it. but most php developers use echo because it is faster and it is sounds cool!
Use what you prefer and easy for you!