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的值将为“ 这是一串很长的文本片段,它们全部连接在一起 。”

3640

被折叠的 条评论
为什么被折叠?



