PHP串联

In PHP it is common to join variables to text and/or HTML tags to produce a complete element: this is referred to as concatenation. The concatenation operator is the period (.) character.

在PHP中,通常将变量连接到文本和/或HTML标记以产生完整的元素:这称为串联。 串联运算符是句点( . )字符。

You can concatenate the value of two variables to create a value for a third:

您可以串联两个变量的值以为第三个变量创建值:

$firstName = "Dudley";
$lastName = "Storey";
$fullName = $firstName.$lastName;

In the example above, $fullName contains the value “DudleyStorey”. If you want a space in the value of $fullName, you can concatenate the variables together with a physical space:

在上面的示例中, $fullName包含值“ DudleyStorey ”。 如果您需要$fullName值中的空格,则可以将变量与物理空间连接在一起:

$fullName = $firstName." ".$lastName;

Naturally you can also echo concatenated strings with variables:

当然,您也可以使用变量来回显串联的字符串:

echo "Your name is ".$firstName." ".$lastName;

Note that joining a number with a string creates a string:

请注意,将数字与字符串连接会创建一个字符串:

$var1 = 23;
$var2 = "skidoo";
$var3 = $var1.$var2;

The value of $var3 is “23skidoo”.

$var3值为“ 23skidoo ”。

It is common to “build up” the value of a single variable through concatenation, especially when the individual pieces are fairly long; for example, when composing an email to be sent via PHP.

通常通过级联来“累积”单个变量的值,尤其是当各个部分相当长时; 例如,编写要通过PHP发送的电子邮件时。

$test = "This is a long ";
$test .= "string of text pieces ";
$test .= "all joined together.";

(Note the use of spaces).

(请注意使用空格)。

At the end of this process the value of $test will be “This is a long string of text pieces all joined together.”

在此过程结束时, $test的值将为“ 这是一串很长的文本片段,它们全部连接在一起 。”

翻译自: https://thenewcode.com/182/PHP-Concatenation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值