PHP Arrays
Arrays in PHP are used to store multiple values in a single variable. PHP supports indexed arrays, associative arrays, and multidimensional arrays.
PHP में arrays का उपयोग एक ही variable में कई values को संग्रहित करने के लिए किया जाता है। PHP में indexed, associative, और multidimensional arrays होते हैं।
Indexed Array
Indexed arrays use numeric indexes to store values.
Indexed arrays में मानों को संग्रहित करने के लिए संख्यात्मक index का उपयोग होता है।
<?php
$colors = array("Red", "Green", "Blue");
echo $colors[1];
?>
Green
Associative Array
Associative arrays use named keys.
Associative arrays में key के रूप में नाम का उपयोग होता है।
<?php
$age = array("John" => 25, "Amit" => 30);
echo $age["Amit"];
?>
30
Multidimensional Array
Multidimensional arrays contain one or more arrays inside an array.
Multidimensional arrays में एक array के अंदर एक या एक से अधिक arrays होते हैं।
<?php
$marks = array(
"Math" => array("Amit" => 85, "John" => 78),
"Science" => array("Amit" => 92, "John" => 88)
);
echo $marks["Science"]["John"];
?>
88