list function
list function သည် array ထဲမှ element များကို
variable များထဲသို့ ထုတ်ယူပေးသည်။
ဖွဲ့စည်းပုံ
list(mixed $var, mixed ...$vars): array
ဥပမာ
Array ထဲမှ element များကို variable များထဲသို့ ထုတ်ယူကြည့်ရအောင်။
<?php
$arr = [1, 2, 3, 4, 5];
list($a, $b, $c, $d, $e) = $arr;
?>
အဆိုပါနည်းဖြင့် $a variable၊ $b variable၊
$c variable၊ $d variable၊ $e variable
များ ရရှိမည်ဖြစ်သည်။
<?php
echo $a; // 1 ကိုပြမည်
echo $b; // 2 ကိုပြမည်
echo $c; // 3 ကိုပြမည်
echo $d; // 4 ကိုပြမည်
echo $e; // 5 ကိုပြမည်
?>
ဥပမာ
Array ၏ ပထမဆုံး element မှမစဘဲ အခြား element မှစ၍ ထုတ်ယူလိုပါက comma ခံထားနိုင်သည်။
<?php
$arr = [1, 2, 3, 4, 5];
list(, $b, $c, $d, $e) = $arr;
?>
အဆိုပါနည်းဖြင့် $b variable၊ $c variable၊
$d variable နှင့် $e variable များ ရရှိမည်ဖြစ်သည်။
<?php
echo $b; // 2 ကိုပြမည်
echo $c; // 3 ကိုပြမည်
echo $d; // 4 ကိုပြမည်
echo $e; // 5 ကိုပြမည်
?>
ဥပမာ
Array ၏ တတိယမြောက် element ကို သာလျှင် variable တစ်ခုအတွင်း သိမ်းဆည်းကြည့်ရအောင်။
<?php
$arr = [1, 2, 3, 4, 5];
list(, , $c) = $arr;
?>
အဆိုပါနည်းဖြင့် $c variable ရရှိမည်ဖြစ်သည်။
<?php
echo $c; // 3 ကိုပြမည်
?>
ဆက်စပ်ကြည့်ရှုရန်
-
extractfunction၊
ထို့အပြင် array ကို variable များအဖြစ် ခွဲခြားပေးသည်