echo multiparameter

There is a very known feature that differs echo and print instructions of PHP: echo takes several parameters, but print doesn’t. Don’t mind echo works silent, well print returns a value depending on execution success.

Just as I’ve faced with echo multiparameter, asked myself: the difference between dot and comma as parameters separator. So, actually said, comma (,) is a real divider, but the dot (.) isn’t, the strings are just get concatenated with it, and echo is used then as one-parameter instruction losing the preferences of the speed of execution.

If it is allowed by code structure the comma has to be used.

stackoverflow.com

So if you join a character 4 million times this is what you get:
echo $str1, $str2, $str3;
About 2.08 seconds
echo $str1 . $str2 . $str3;
About 3.48 seconds

Discussion

Oh, just in case: it’s about PHP!

This entry was posted in PHP, web. Bookmark the permalink.