PHP : Echo or Print

PHP : Using Echo or Print
When we write a program using PHP, we often use echo and print commands, but we do not know what is the effects of using echo or print. Sometimes we can be dizzy between two options, use echo or print when you want to display the contents of a variable, or just display text alert than usual as a process that has been done. Echo or Print? Echo or Print? Echo or Print? and so on ... A little confused indeed. In addition to the print and echo, PHP also provides many alternatives for the other syntax.
Many programmer experienced in web programming, they turns out tend to use echo rather than print, then what reason?
Let us understood better. A PHP language developers have to do testing, and the result is the echo was 15% faster process than the print function (in millisecond). And it is common knowledge that if the print is a function that returns the value in it (Returning value). And there's another reason why most developers prefer to use echo rather than print, another reason is, time efficiency, because the echo was only requires 4 letters to be typed, while the print it has 5 letters to be typed. But this is reality. A lazy programmer to write the letter 't'. And this has become a natural instinct of a man, chose the shorter term. After all the same.
Okay, for further efficiency is the use of:
echo "$variable1 and". "$Variable2 to be displayed". "Put here";

It takes a lot of resources, because the dot has a function to add the contents of a variable, not connecting or forward. The difference between adding to the forward is like this:
Adding means opening a new variable and add the contents into the variable, then closes the variable.
While connecting, or continue means variables that have been opened his residence to continue the content of variable.
Adding consists of three processes, while connecting or forwarding just doing one process.
Best use of echo is as follows:
echo $variable , "and", $variable2, "which will be displayed", "put here";

Each word here is separated only as a simulation of real cases. Echo is better to use comma connect to each variable, or display the text, not dot. So that process can be faster, and fewer resources required.


Post a Comment