PHP တွင် array_chunk function သည်အလွန်အသုံး 0 င်သောကိရိယာတစ်ခုဖြစ်သည်။ ယနေ့တွင်ကျွန်ုပ်တို့သည် array_chunk ကို အသုံးပြု. အသုတ်နှင့်အပိုင်း (activars arrays) ကိုအသုတ်နှင့်အပိုင်း (Association Arrays) ကိုမည်သို့မိတ်ဆက်ပေးမည်။
Array_chunk function သည် stary တစ်ခုစီကိုသေးငယ်တဲ့ strarrays (subarrays) သို့ကွဲပြားစေပြီးဒီ subarrays ရေးထားတဲ့ခင်းကျင်းမှုအသစ်တစ်ခုကိုပြန်ပို့လိုက်တယ်။ ဒါဟာအဓိက parameters နှစ်ခုရှိပါတယ်:
ခင်းကျင်းခြင်း - ခွဲထွက်ရန်ခင်းကျင်းခြင်း။
အရွယ်အစား : တစ်ခုချင်းစီကို subarray ၏အရွယ်အစား။
ထို့အပြင် Array_chunk function တွင်တတိယ parameter, $ presfet_keys, $ Presentify_keys , မှန်ကန် ရန်သတ်မှတ်ထားပါကမူရင်းခင်းကျင်းမှု၏သော့အမည်ကိုဆက်လက်ထိန်းသိမ်းထားလိမ့်မည်။
ကျွန်ုပ်တို့တွင် Associative Array (Key-value pair) ဖြစ်သောအဘိဓာန်ဒေတာများရှိသည်ဆိုပါစို့။ ကျနော်တို့သတ်မှတ်ထားသောအရွယ်အစားအားဖြင့် batch အရွယ်အစားခွဲဖို့ချင်တယ်။ ထို့နောက်တိကျသောဥပမာတစ်ခုကိုကြည့်ကြစို့။
<?php
// အဘိဓါန်အဘိဓာန်
$dictionary = [
'apple' => 'A fruit that is typically red or green.',
'banana' => 'A long yellow fruit.',
'cherry' => 'A small round fruit, typically red or black.',
'date' => 'A sweet fruit from the date palm tree.',
'elderberry' => 'A dark purple fruit from the elder tree.',
'fig' => 'A sweet fruit with a soft texture.',
'grape' => 'A small, round fruit that comes in clusters.',
'honeydew' => 'A sweet melon with green flesh.',
];
// အသုံးပြု array_chunk အဘိဓာန်ဒေတာ segent
$chunkedArray = array_chunk($dictionary, 3, true);
// ပုံနှိပ်ခြင်း
echo "<pre>";
print_r($chunkedArray);
echo "</pre>";
?>
ဤဥပမာတွင်ကျွန်ုပ်တို့သည်အချက်အလက်များပါ 0 င်သည့်အကောင်အထည်ဖော်မှုအတွဲ (3) ခုပါ 0 င်သည့်အဘိဓာန်တစ်ခုစီတွင်အဘိဓာန်တစ်ခုချင်းစီတွင်အဘိဓာန်တစ်ခု စီသို့ခွဲခြားထားသည်။ တတိယ parameter သည် အဘိဓာန် (I.E. Apple , Banana , Cherry စသည်တို့) ကိုထိန်းသိမ်းရန်ဖြစ်သည်။ အကယ်. မှန်ကန်သော ပြောင်းလဲမှုကို မှားယွင်းစွာ ပြောင်းလဲပါကခွဲစိတ်မှု၏သော့များသည်ဂဏန်းညွှန်းကိန်းများဖြစ်လာလိမ့်မည်။
ကျနော်တို့အထက်ပါအတိုင်းဒေတာများကိုခွဲခြား, output ရလဒ်ကိုအောက်ပါအတိုင်းဖြစ်သည်ဆိုပါစို့။
Array
(
[0] => Array
(
[apple] => A fruit that is typically red or green.
[banana] => A long yellow fruit.
[cherry] => A small round fruit, typically red or black.
)
[1] => Array
(
[date] => A sweet fruit from the date palm tree.
[elderberry] => A dark purple fruit from the elder tree.
[fig] => A sweet fruit with a soft texture.
)
[2] => Array
(
[grape] => A small, round fruit that comes in clusters.
[honeydew] => A sweet melon with green flesh.
)
)
သင်မြင်နိုင်သည့်အတိုင်းအဘိဓာန်မျိုးစုံ subarrays သို့ခွဲခြားထားသည်, subarray တစ်ခုစီတွင်ပစ္စည်း 3 ခုစီပါ 0 င်သည်။
များသောအားဖြင့်ကျွန်ုပ်တို့၏အဘိဓာန်များသည် URLs များပါ 0 င်နိုင်သည်။ ဥပမာအားဖြင့်, ကျွန်ုပ်တို့တွင်အမျိုးမျိုးသောဆောင်းပါးများအတွက်လင့်ခ်အချက်အလက်များပါ 0 င်မှုဆိုင်ရာအချက်အလက်များပါ 0 င်နိုင်သည်။ M66.net နှင့်အတူ URL အားလုံး၏ဒိုမိန်းအမည်များကိုအစားထိုးရန်လိုသည်ဟုယူဆသော URL နှင့်အတူအဘိဓာန်ရှိသောအချက်အလက်များဖြစ်သည်။
<?php
// ခါးပတ် URL အိမ်ပြင်ပစ်
$dictionaryWithUrls = [
'article1' => 'https://example.com/article/1',
'article2' => 'https://example.com/article/2',
'article3' => 'https://example.com/article/3',
'article4' => 'https://example.com/article/4',
];
// ပြန်လည်နေရာချ URL ဒိုမိန်းအမည်
foreach ($dictionaryWithUrls as $key => $url) {
$dictionaryWithUrls[$key] = preg_replace('/https?:\/\/[^\/]+/', 'https://m66.net', $url);
}
// အသုံးပြု array_chunk အဘိဓာန်ဒေတာ segent
$chunkedArrayWithUrls = array_chunk($dictionaryWithUrls, 2, true);
// ပုံနှိပ်ခြင်း
echo "<pre>";
print_r($chunkedArrayWithUrls);
echo "</pre>";
?>
ဤဥပမာတွင်ကျွန်ုပ်တို့သည် M66.net နှင့်အတူ URL domain name တွင် URL domain name ကိုအစားထိုးရန် Preg_replace function ကိုအသုံးပြုသည်။ ကွဲပြားသောဒေတာများကို 2 ခုနှင့်အညီ subarrays မျိုးစုံသို့ခွဲခြားထားသည်။
array_chunk သည်အသုတ်အတွက်အဆင်ပြေသောအရွယ်အစားဖြင့်အများကိန်းဒေတာအမြောက်အမြားကိုခွဲခြားရန်အထောက်အကူပြုသောအစွမ်းထက်သော function တစ်ခုဖြစ်သည်။ URLs များသို့မဟုတ်အခြားတန်ဖိုးများကိုလိုအပ်သောအချက်အလက်များတွင်လည်းအစားထိုးနိုင်သည်။ အချက်အလက်များကိုပိုမိုကောင်းမွန်စွာ စုစည်း. လုပ်ဆောင်ရန်ဤနည်းလမ်းကိုသုံးနိုင်သည်။
array_chunk ကို သုံး. အချက်အလက်များကိုအသုတ်နှင့်အစိတ်အပိုင်းများကိုမည်သို့နားလည်ရမည်ကိုပိုမိုနားလည်ရန်ဤဆောင်းပါးကသင့်အားပိုမိုကောင်းမွန်သောနားလည်မှုကိုပိုမိုနားလည်ရန်မျှော်လင့်ပါ။ သင့်တွင်အခြားမေးခွန်းများသို့မဟုတ်ပိုမိုရှုပ်ထွေးသောလိုအပ်ချက်များရှိပါကမေးခွန်းများမေးရန်လွတ်လပ်စွာခံစားပါ။