PHP တွင် concatenation operator သည် string နှစ်ခုကိုကြိုးတစ်ချောင်းထဲသို့ဆွဲယူရန်အသုံးပြုသည်။ အသုံးအများဆုံး string ကို concatenation အော်ပရေတာသည် "" ဟူသောစကားလုံးနှစ်လုံးကိုပေါင်းစပ်ထားသောကြိုးနှစ်ချောင်းကိုပေါင်းစပ်ထားသော "။ "
သငျသညျ "two strings နှစ်ခု concatenate နိုင်ပါတယ်" ။ " အော်ပရေတာ။ ၎င်းသည် PHP တွင်အခြေခံအကျဆုံး string ကိုစစ်ဆင်ရေးဖြစ်သည်။
$str1 = "Hello, ";
$str2 = "world!";
echo $str1 . $str2; // ထုတ်လုပ်ခြင်း: Hello, world!
"။ =" အော်ပရေတာနှင့်အတူ, အခြား string ကို၏အဆုံးမှ string ကိုဖြည့်စွက်နိုင်ပါတယ်:
$str1 = "Hello, ";
$str1 .= "world!";
echo $str1; // ထုတ်လုပ်ခြင်း: Hello, world!
string concatenation လုပ်နေသည့်အခါ, variable နှစ်ခုလုံး string ကိုအမျိုးအစားများဖြစ်ကြောင်းသေချာပါစေ။ အကယ်. variable များထဲမှတစ်ခုသည်နံပါတ်တစ်ခုသို့မဟုတ်အခြားအမျိုးအစားတစ်ခုဖြစ်ပါက PHP သည်၎င်းကို string တစ်ခုသို့ပြောင်းရန်ကြိုးစားလိမ့်မည်။ ပြောင်းလဲခြင်းပျက်ကွက်လျှင်သတိပေးချက်တစ်ခုပစ်ချသည်။
$str1 = "Hello, ";
$str2 = 123;
echo $str1 . $str2; // ထုတ်လုပ်ခြင်း: Hello, 123 (နံပါတ်များ strings မှကူးပြောင်းနေကြသည်)
string concatenation ကို concatenation နှစ်ခု concatenated strings ကိုအပြည့်အဝ string ကိုသို့ spliced နေကြသည်။ သင်ကြိုးပေါင်းများစွာကိုသင်သဘောတူရန်လိုအပ်ပါက concatenation operator ကိုအကြိမ်ကြိမ်အသုံးပြုနိုင်သည်။
$str1 = "Hello, ";
$str2 = "world!";
$str3 = "How ";
$str4 = "are ";
$str5 = "you?";
echo $str1 . $str2 . $str3 . $str4 . $str5; // ထုတ်လုပ်ခြင်း: Hello, world! How are you?
connections များသည်ကြိုးများစွာကို concatenate နိုင်သော်လည်း code ၏ readability ကိုတိုးတက်စေရန်ဆက်သွယ်မှုအစဉ်အဆက်ကိုရှင်းလင်းရန်ကွင်းခတ်များကိုအသုံးပြုရန်အကြံပြုသည် -
$str1 = "Hello, ";
$str2 = "world!";
$str3 = "How ";
$str4 = "are ";
$str5 = "you?";
echo ($str1 . $str2) . ($str3 . $str4 . $str5); // ထုတ်လုပ်ခြင်း: Hello, world! How are you?
ကွင်းခတ်များကိုအသုံးပြုခြင်းသည်ဆက်သွယ်မှုများပိုမိုရှင်းလင်းစွာပြုလုပ်နိုင်ပြီးကုဒ်၏ဖတ်နိုင်မှုကိုတိုးတက်စေနိုင်သည်။