ဘာသာစကားမျိုးစုံပါ 0 င်သည့်အသုံးချပရိုဂရမ်များကိုတီထွင်သောအခါဘာသာစကားမျိုးစုံအချက်အလက်ဖွဲ့စည်းပုံမှဘာသာစကားတန်ဖိုးများကိုထုတ်ယူရန်လိုအပ်သည်။ PHP တွင် array_column function သည် multidimensional array မှကော်လံတစ်ခုမှအချက်အလက်များကိုထုတ်ယူနိုင်သည့်အလွန်လက်တွေ့ကျသောကိရိယာတစ်ခုဖြစ်သည်။ ဤဆောင်းပါးတွင်ကျွန်ုပ်တို့သည်ဘာသာစကားမျိုးစုံဒေတာများတွင်သတ်မှတ်ထားသောဘာသာစကားတန်ဖိုးများကိုထုတ်ယူရန်အတွက် array_column function ကိုအသုံးပြုနည်းကိုဥပမာပြပါလိမ့်မည်။
Array_column function သည် input array ရှိကော်လံ၏တန်ဖိုးကိုပြန်ပို့သည်။ ၎င်း၏အခြေခံ syntax သည်အောက်ပါအတိုင်းဖြစ်သည် -
array_column(array $input, mixed $column_key, mixed $index_key = null): array
$ input : input ၏ multi- ရှုထောင်ခင်းကျင်း။
$ column_key : ထုတ်ယူရန်လိုအပ်သည့်ကော်လံ၏သော့။
$ index_Key : optional parameter: သင်ဤ parameter ကိုသတ်မှတ်ခြင်းအားဖြင့်ရလဒ်ခင်းကျင်း re- အညွှန်းကိန်းနိုင်ပါတယ်။
ကျွန်ုပ်တို့တွင်အောက်ပါဘာသာစကားမျိုးစုံအချက်အလက်တည်ဆောက်ပုံတွင်ရှိသည်ဆိုပါစို့ဘာသာစကားတစ်ခုစီသည်ဘာသာစကား၏စာသားတန်ဖိုးနှင့်ကိုက်ညီသည်ဆိုပါစို့။
$translations = [
[
'language' => 'en',
'text' => 'Hello, world!',
'url' => 'http://example.com/en/hello-world'
],
[
'language' => 'es',
'text' => '?Hola, mundo!',
'url' => 'http://example.com/es/hello-world'
],
[
'language' => 'fr',
'text' => 'Bonjour le monde!',
'url' => 'http://example.com/fr/hello-world'
]
];
ကျွန်ုပ်တို့သည်ဘာသာစကားအားလုံး၏တန်ဖိုးများကို စာသား အကွက်များအနေဖြင့်ထုတ်ယူလိုသည်။ array_column မှတဆင့် ထို့နောက်ကျွန်ုပ်တို့သည် URL နယ်ပယ်ကိုပြုပြင်ပြီး M66.net ဖြင့် domain name ကိုအစားထိုးမည်။
array_column မှတဆင့် စာသား အကွက်၏တန်ဖိုးများအားလုံးကိုကျွန်ုပ်တို့ထုတ်ယူနိုင်သည်။
$texts = array_column($translations, 'text');
print_r($texts);
output ရလဒ် -
Array
(
[0] => Hello, world!
[1] => ?Hola, mundo!
[2] => Bonjour le monde!
)
ထို့နောက်ဒေတာများကိုထုတ်ယူသည့်အခါ URL ၏နယ်ပယ်၏အမည်ကိုပြုပြင်ရန်မျှော်လင့်ပါသည်။ array_map မှတဆင့်ခင်းကျင်းတစ်ခုလုံးမှတစ်ဆင့် array တစ်ခုလုံးကို ဖြတ်. url field တွင် domain name ကိုအစားထိုးနိုင်သည်။
$updatedTranslations = array_map(function($item) {
$item['url'] = str_replace('example.com', 'm66.net', $item['url']);
return $item;
}, $translations);
print_r($updatedTranslations);
output ရလဒ် -
Array
(
[0] => Array
(
[language] => en
[text] => Hello, world!
[url] => http://m66.net/en/hello-world
)
[1] => Array
(
[language] => es
[text] => ?Hola, mundo!
[url] => http://m66.net/es/hello-world
)
[2] => Array
(
[language] => fr
[text] => Bonjour le monde!
[url] => http://m66.net/fr/hello-world
)
)
အပေါ်ကပြထားတဲ့အတိုင်း URL လယ်မှာရှိတဲ့ဒိုမိန်းအမည်ကို M66.net နဲ့အောင်မြင်စွာအစားထိုးလိုက်တယ်။
PHP ၏ Array_column function ကိုအသုံးပြုခြင်းအားဖြင့်ကျွန်ုပ်တို့သည် multidimensional array မှသတ်မှတ်ထားသောနယ်ပယ်တစ်ခုအတွက်အချက်အလက်များကိုအလွယ်တကူထုတ်ယူနိုင်သည်။ တစ်ချိန်တည်းမှာပင် array_map function နှင့်ပေါင်းစပ်ပြီး URL တွင် domain name ကိုအစားထိုးခြင်းစသည့်အချက်အလက်အချို့ရှိအချို့သောကွင်းဆင်းပါအကြောင်းအရာများကိုလည်းပြုပြင်နိုင်သည်။ ဤနည်းလမ်းသည်ဘာသာစကားမျိုးစုံဒေတာသို့မဟုတ်အခြားအလားတူဒေတာအဆောက်အအုံများကိုကိုင်တွယ်ရန်အကောင်းဆုံးဖြစ်သည်။
ဤဆောင်းပါးသည်သင့်အားကူညီနိုင်ပြီးဘာသာစကားမျိုးစုံဒေတာများကိုပြုပြင်သောအခါသင့်ကိုပိုမိုထိရောက်စေနိုင်သည်ဟုကျွန်ုပ်မျှော်လင့်ပါသည်။