Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Arrays

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Array ဆိုတာ value များစွာကို variable တစ်ခုတည်းထဲမှာ စုထားတဲ့ structure ပါ။ Menu list, product list, user profile, cart items စတာတွေမှာ array တွေကိုအရမ်းအသုံးများပါတယ်။ Indexed array က number index သုံးပြီး Associative array က name key သုံးပါတယ်။

php
<?php
// Indexed array
$skills = ["HTML", "CSS", "PHP"];
echo $skills[2] . "<br>";

// Associative array
$user = [
  "name" => "Mya Mya",
  "role" => "Student"
];
echo $user["name"] . " is a " . $user["role"];
?>
You should see
PHP Mya Mya is a Student

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Array index က 0 ကစတာကိုမေ့ပြီး $skills[3] လို့ခေါ်ရင် undefined offset ဖြစ်နိုင်ပါတယ်။
Arrays | Thuta Learning