PHP ပရိုဂရမ်တွင် strips -function သည်အလွန်အသုံးများသော string privulation function ဖြစ်သည်။ ၎င်းသည် string တစ်ခုကိုအခြား string တစ်ခုတွင်ပထမဆုံးပေါ်လာသည့်နေရာကိုရှာဖွေရန်အသုံးပြုသည်။ ၎င်း၏အသုံးပြုမှုယေဘုယျအားဖြင့်:
stripos($haystack, $needle);
$ haystack သည်ရှာဖွေရန်အတွက် string ကိုနှင့် $ အပ်သည် သင်ရှာဖွေနေသည့်အလွှာဖြစ်သည်။ အကယ်. $ အပ်ကို ရှာတွေ့ပါကအလွှာ၏အနေအထားကို ဒေါ်လာ haystack ဖြင့်ပြန်ပို့သည်။
switch statement သည်ဖြစ်နိုင်ခြေရှိသောဌာနခွဲတရားရုံးများကိုလုပ်ဆောင်ရန်အတွက်အသုံးပြုလေ့ရှိသောဌာနခွဲတရားရုံးများ, နံပါတ်များ, PHP ရိုးရာ switch ထုတ်ပြန်ချက်များသည် strips များကို အသုံးပြု. string နှင့်ကိုက်ညီမှုမရှိပါ။
ဤရိုးရှင်းသောကုဒ်ကိုသုံးသပ်ကြည့်ပါ။
<?php
$searchString = "Hello World";
switch (stripos($searchString, "hello")) {
case 0:
echo "Found 'hello' at the start!";
break;
case false:
echo "'hello' not found!";
break;
default:
echo "Found 'hello' at position " . stripos($searchString, "hello");
}
?>
မျက်နှာပြင်ပေါ်မှာ, strips -s သည် ကိန်းဂဏန်းများ (အလွှာ၏တည်နေရာကိုကိုယ်စားပြုခြင်း) သို့မဟုတ်မှားယွင်းသောကြောင့်သို့မဟုတ်မှားယွင်းသောကြောင့်အဘယ်ကြောင့်ဆိုသော် STARPOS (substring ၏တည်နေရာကိုကိုယ်စားပြုသည်) သို့မဟုတ် မှားယွင်းသော ကြောင့်ဖြစ်သည်။ သို့သော်ပြ problems နာအချို့ရှိပါသည်။
switch statement သည်အခြေအနေကိုဆုံးဖြတ်သည့်အခါအမျိုးအစားပြောင်းလဲမှုကိုလုပ်ဆောင်လိမ့်မည်။ ဆိုလိုသည်မှာ strips များသည် ကိန်းဂဏန်းများကိုပြန်လည်ရောက်ရှိစေလျှင် , PHP တွင် 0 Boolean fiss ဟုသတ်မှတ်သည်။ switch statement in switch switched in: case 0: false false:, မှန်ကန်စွာကိုက်ညီရန်ပျက်ကွက်ခြင်း။
အထူးသဖြင့် strippos မှပြန်လာ 0 ကို Boolean Fust သို့ပြောင်းလဲခြင်းသို့ကူးပြောင်းခြင်းကို switch မှပြောင်းလဲလိမ့်မည်။
ဤပြ problem နာကိုရှောင်ရှားရန် strips များ ကပြန်လာသောတန်ဖိုးများကိုရှုပ်ထွေးခြင်းမရှိကြောင်းသေချာစေရန်ရှင်းလင်းပြတ်သားသောအမျိုးအစားစစ်ဆေးခြင်းကိုသင်အသုံးပြုနိုင်သည်။ ဥပမာအားဖြင့်, သင်သည်တင်းကျပ်သောနှိုင်းယှဉ်မှုများအတွက် === ကို သုံး နိုင်သည် ။
ဒီနေရာမှာတိုးတက်လာသောဗားရှင်းဖြစ်သည်။
<?php
$searchString = "Hello World";
$position = stripos($searchString, "hello");
if ($position === false) {
echo "'hello' not found!";
} elseif ($position === 0) {
echo "Found 'hello' at the start!";
} else {
echo "Found 'hello' at position " . $position;
}
?>
Swipos ကို switch statements တွင် တိုက်ရိုက်မသုံးနိုင်ပါ switch သည် အမျိုးအစားပြောင်းလဲခြင်းပြုလုပ်လိမ့်မည် ။ ဒီပြ problem နာကိုရှောင်ရှားရန် switch အစား stats ကိုအစား ဖော်ပြ ခြင်းနှင့်တင်းကျပ်သောအမျိုးအစားကိုလုပ်ဆောင်ပါကအသုံးပြုရန်အကြံပြုသည်။