PHP字符串拼接的方法有以下幾種:
$str1 = "Hello";
$str2 = "World";
$result = $str1 . $str2;
echo $result; // 輸出:HelloWorld
$name = "John";
$age = 25;
$result = "My name is $name and I am $age years old.";
echo $result; // 輸出:My name is John and I am 25 years old.
$name = "John";
$age = 25;
$result = sprintf("My name is %s and I am %d years old.", $name, $age);
echo $result; // 輸出:My name is John and I am 25 years old.
$str = "Hello";
$str .= " World";
echo $str; // 輸出:Hello World
$array = array("Hello", "World");
$str = implode(" ", $array);
echo $str; // 輸出:Hello World