PHP array_column() လုပ်ဆောင်ချက်
ဥပမာ
မှတ်တမ်းအစုံမှ နောက်ဆုံးအမည်များ၏ ကော်လံကို ရယူပါ-
<?php
// An array that represents a possible record set returned from a database
$a = array(
array(
'id' => 5698,
'first_name' => 'Peter',
'last_name' => 'Griffin',
),
array(
'id' => 4767,
'first_name' => 'Ben',
'last_name' => 'Smith',
),
array(
'id' => 3809,
'first_name' => 'Joe',
'last_name' => 'Doe',
)
);
$last_names = array_column($a, 'last_name');
print_r($last_names);
?>
အထွက်-
Array
(
[0] => Griffin
[1] => Smith
[2] => Doe
)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
array_column() function သည် input array ရှိ ကော်လံတစ်ခုမှ တန်ဖိုးများကို ပြန်ပေးသည်။
အထားအသို
array_column(array, column_key, index_key)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
array | Required. Specifies the multi-dimensional array (record-set) to use. As of PHP 7.0, this can also be an array of objects. |
column_key | Required. An integer key or a string key name of the column of values to return. This parameter can also be NULL to return complete arrays (useful together with index_key to re-index the array) |
index_key | Optional. The column to use as the index/keys for the returned array |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | input array မှ ကော်လံတစ်ခုတည်းကို ကိုယ်စားပြုသည့် တန်ဘိုးတစ်ခု၏ array ကို ပြန်ပေးသည်။ |
---|---|
PHP ဗားရှင်း- | 5.5+ |
နောက်ထပ် ဥပမာများ
ဥပမာ
"id" ကော်လံဖြင့် အညွှန်းပြုထားသော မှတ်တမ်းအစုံမှ အမည်များ၏ ကော်လံကို ရယူပါ-
<?php
// An array that represents a possible record set returned from a database
$a = array(
array(
'id' => 5698,
'first_name' => 'Peter',
'last_name' => 'Griffin',
),
array(
'id' => 4767,
'first_name' => 'Ben',
'last_name' => 'Smith',
),
array(
'id' => 3809,
'first_name' => 'Joe',
'last_name' => 'Doe',
)
);
$last_names = array_column($a, 'last_name', 'id');
print_r($last_names);
?>
အထွက်-
Array
(
[5698] => Griffin
[4767] => Smith
[3809] => Doe
)
❮ PHP Array အကိုးအကား