I just found that this will work:
echo $value , " continue";
but this does not:
return $value , " continue";
While .
works instead of ,
in both the echo
and return
statements.
What is the difference between a period and a comma here?
concatenation means you are combining both variables(only strings) into one. But when you use comma it prints both the output separately but you can't see it on the output console.
This is because PHP with dots joins the string first and then outputs them, while with commas just prints them out one after the other.
The use of the comma (,) is to help with shortening long sentences, or joining two sentences, or even to list a number of words within one sentence. If a long sentence leaves you out of breath when you are reading it out loud, add a comma to give a brief breathing break to the reader. The period or full-stop (.) ends a sentence.
But echo allows a list of expressions where each expression is separated by a comma. But note that since echo is not a function but a special language construct, wrapping the expression list in parenthesis is illegal. Show activity on this post. You also have to note that echo as a construct is faster with commas than it is with dots.
But the comma doesn't concatenate and this is why the return statement won't work. echo is a language construct that can take multiple expressions which is why the comma works: void echo ( string $arg1 [, string $... ] ) Use the dot for concatenation. Show activity on this post.
You also have to note that echo as a construct is faster with commas than it is with dots. It almost takes half the time as you can see above. This is because PHP with dots joins the string first and then outputs them, while with commas just prints them out one after the other. We are talking about fractions, but still. Show activity on this post.
return
only allows one expression, but echo
allows a list of expressions where each expression is separated by a comma.
But note that since echo
is not a function but a special language construct, wrapping the expression list in parenthesis is illegal.
You also have to note that echo
as a construct is faster with commas than it is with dots.
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
It almost takes half the time as you can see above.
This is because PHP with dots joins the string first and then outputs them, while with commas just prints them out one after the other.
We are talking about fractions of a second, but still.
Original Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With