什么是 .(点)在PHP中做?
2022-08-30 12:00:12
以下命令在 PHP 中有什么作用?
. $string // ($string is something which I declared in the program)
以下命令在 PHP 中有什么作用?
. $string // ($string is something which I declared in the program)
就其本身而言,这根本不起作用(它不是有效的语法)。但是,如果您有类似这样的东西:
<?php
$string1 = "Hello ";
$string2 = "world!";
$string = $string1 . $string2;
echo $string;
?>
您将看到 .是字符串串联运算符。Hello world!
.
单独来看,这是一个语法错误。点是串联运算符,用于将其参数转换为字符串并连接它们。例如.
<?php
$string = "x";
$s = 42 . $string;
// $s is now "42x"