Hướng dẫn what is the result of combining string with another data type in php? - kết quả của việc kết hợp chuỗi với một kiểu dữ liệu khác trong php là gì?

Có hai toán tử chuỗi. Đầu tiên là toán tử nối ('.'), Trả về sự kết hợp của các đối số bên phải và trái của nó. Thứ hai là toán tử gán kết hợp ('.='), điều này nối liền đối số ở phía bên phải vào đối số ở phía bên trái. Vui lòng đọc các nhà khai thác chuyển nhượng để biết thêm thông tin.string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information.

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>

K.alex ¶

9 năm trước

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:

$a

= '12345';// This works:
echo "qwe{$a}rty"; // qwe12345rty, using braces
echo "qwe" . $a . "rty"; // qwe12345rty, concatenation used

// Does not work:

echo 'qwe{$a}rty'; // qwe{$a}rty, single quotes are not parsed
echo "qwe$arty"; // qwe, because $a became $arty, which is undefined?>

Anders Dot Benke tại Telia Dot Com ¶

18 năm trước

A word of caution - the dot operator has the same precedence as + and -, which can yield unexpected results.

Example:

$var = 3;

echo "Result: " . $var + 3;
?>

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
0

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
1

$var = 3;

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
3

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
4

Stephen Clay ¶

16 năm trước

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
5

hexidecimalgadget tại hotmail dot com ¶

13 năm trước

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
6

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
7

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
4

Mariusads :: at :: helpia.com

14 năm trước

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
9

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:0

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:1

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:2

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
4

Biziclop ¶

1 tháng trước

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:4

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:5

As for me, curly braces serve good substitution for concatenation, and they are quicker to type and code looks cleaner. Remember to use double quotes (" ") as their content is parced by php, because in single quotes (' ') you'll get litaral name of variable provided:6

$a "Hello ";
$b $a "World!"// now $b contains "Hello World!"$a "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
4

Tại sao bạn muốn kết hợp các chuỗi trong PHP?

Hóa ra đây là một nhiệm vụ phổ biến và hữu ích trong PHP: Kết hợp hai chuỗi với nhau để chúng ta có một chuỗi duy nhất hoặc một cái gì đó mà chúng ta có thể lặp lại với màn hình.so that we get a single string or something that we can echo to the screen.

Điều gì xảy ra khi hai chuỗi được thêm vào với nhau?

Kết nối là quá trình nối thêm một chuỗi vào cuối chuỗi khác. Bạn nối các chuỗi bằng cách sử dụng toán tử +. Đối với các chuỗi chữ và hằng số chuỗi, sự kết hợp xảy ra tại thời điểm biên dịch; Không có sự kết hợp thời gian chạy xảy ra. Đối với các biến chuỗi, việc kết hợp chỉ xảy ra tại thời điểm chạy.. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

Điều gì sẽ xảy ra nếu bạn kết hợp các chuỗi với số nguyên?

Trong hầu hết các ngôn ngữ lập trình khác, nếu chúng ta nối một chuỗi với số nguyên (hoặc bất kỳ loại dữ liệu nguyên thủy nào khác), ngôn ngữ sẽ chăm sóc chúng thành một chuỗi và sau đó kết hợp nó. Tuy nhiên, trong Python, nếu bạn cố gắng kết hợp một chuỗi với số nguyên bằng toán tử +, bạn sẽ gặp lỗi thời gian chạy.you will get a runtime error.

Làm thế nào kết nối giữa chuỗi và biến số được thực hiện trong PHP?

Các chuỗi dự bị và nối vào PHP..
Bạn có thể sử dụng toán tử nối.Nếu bạn muốn tham gia chuỗi và gán kết quả cho biến thứ ba hoặc xuất nó.....
Bạn có thể sử dụng toán tử phân công nối.= Nếu bạn muốn tham gia các chuỗi và gán kết quả cho cùng một biến ..