如何在 PHP 中连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5344047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to concat string in PHP
提问by user657601
I want to do like this:
我想这样做:
$string = "";
$string += "lol"; //maybe =+ > tried but both not working
But it isn't working, anyone suggestions? Google isn't making my life easy (cant search characters like = or +)
但它不起作用,有人建议吗?Google 并没有让我的生活变得轻松(无法搜索 = 或 + 等字符)
回答by Marc B
In PHP, string concatenation is done with the .
operator:
在 PHP 中,字符串连接是通过.
运算符完成的:
$string .= 'lol';
+
is for addition.
+
是为了加法。
回答by Marcel
$str = "";
while(...){
$str .= "lol.";
}
Input or place the ellipses with your loop condition, += is an add and increment operator.
输入或放置带有循环条件的省略号,+= 是加法和增量运算符。