문제

What are the differences in the results of these three strings:

  1. echo "Hello" . "World! <br />";

  2. echo "Hello"; echo "World!" , "<br />";

  3. echo "Hello" , "World!" , "<br />";

Is there any preferred way to concatenate strings or are they all acceptable?

도움이 되었습니까?

해결책

The preferred way is to use the dot.

Most php programmers don't even know it is possible to use the comma. Having two echo statements is less readable, and slightly less performant.

다른 팁

The concatenation operator is '.', the comma doesn't concatenate. In the examples you made, only the first one is concatenation.

On the other side, the echo construct, accepts many parameters which are separated by commas.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top