PHP字符串串联 [英] PHP string concatenation

查看:82
本文介绍了PHP字符串串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道是否可以连接字符串,如下所示?如果没有,那么还有什么选择呢?

I need to know if its possible to concatenate strings, as follows ? and if not, what is the alternative of doing so ?

while ($personCount < 10) {
$result+= $personCount . "person ";
}

echo $result;

它应该看起来像1 person 2 person 3人等.

您不能在连接中使用+符号,那么有什么替代方法?

You cann't use the + sign in concatenation so what is the alternative ?

推荐答案

只需使用.进行串联. 而且您错过了$personCount增量!

Just use . for concatenating. And you missed out the $personCount increment!

while ($personCount < 10) {
    $result .= $personCount . ' people';
    $personCount++;
}

echo $result;

这篇关于PHP字符串串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆