PHP Multidimensional Array एक ऐसा array होता है जिसमें एक array के अंदर एक और array हो सकता है। इसे nested array भी कहा जाता है। Multidimensional Arrays का उपयोग तब किया जाता है, जब डेटा को टेबल या ग्रिड की तरह व्यवस्थित करना हो।
Types of Multidimensional Arrays:
- Two-dimensional Array (2D Array): एक ऐसा array जिसमें हर element एक और array है।
- Three-dimensional Array (3D Array): एक ऐसा array जिसमें elements के अंदर और arrays हो सकते हैं।
Php Multidimensional Array के Features:
- Complex डेटा को store करने के लिए उपयोगी।
- Array के अंदर arrays को organized रूप से store किया जाता है।
- डेटा को rows और columns के रूप में represent करने में मदद करता है।
- Loop के जरिए आसानी से manage किया जा सकता है।
Php Multidimensional Array को Define कैसे करें?
Two-dimensional Array (2D Array):
<?php
// Students के नाम और उनके subjects के marks को store करना
$students = [
["Ravi", 85, 90, 78], // पहला student
["Pooja", 92, 88, 95], // दूसरा student
["Amit", 76, 89, 80] // तीसरा student
];
?>PHPThree-dimensional Array (3D Array):
<?php
// Products की category और उनके details को store करना
$products = [
"Electronics" => [
["Laptop", "Dell", 50000],
["Mobile", "Samsung", 20000]
],
"Appliances" => [
["Washing Machine", "LG", 30000],
["Refrigerator", "Whirlpool", 25000]
]
];
?>PHPMultidimensional Array को Access कैसे करें?
Two-dimensional Array को Access करना:
$students = [
["Ravi", 85, 90, 78],
["Pooja", 92, 88, 95],
["Amit", 76, 89, 80]
];
// Element को access करना
echo $students[0][0]; // Output: Ravi
echo $students[1][1]; // Output: 92
echo $students[2][2]; // Output: 89<?php
$students = [
["Ravi", 85, 90, 78],
["Pooja", 92, 88, 95],
["Amit", 76, 89, 80]
];
// Element को access करना
echo $students[0][0]; // Output: Ravi
echo $students[1][1]; // Output: 92
echo $students[2][2]; // Output: 89
?>PHPThree-dimensional Array को Access करना:
<?php
$products = [
"Electronics" => [
["Laptop", "Dell", 50000],
["Mobile", "Samsung", 20000]
],
"Appliances" => [
["Washing Machine", "LG", 30000],
["Refrigerator", "Whirlpool", 25000]
]
];
// Element को access करना
echo $products["Electronics"][0][0]; // Output: Laptop
echo $products["Appliances"][1][1]; // Output: Whirlpool
?>PHPMultidimensional Array को Loop के साथ Access करना:
Two-dimensional Array:
<?php
$students = [
["Ravi", 85, 90, 78],
["Pooja", 92, 88, 95],
["Amit", 76, 89, 80]
];
// Loop के साथ data access करना
foreach ($students as $student) {
foreach ($student as $detail) {
echo $detail . " ";
}
echo "\n";
}
?>PHP
Three-dimensional Array:
<?php
$products = [
"Electronics" => [
["Laptop", "Dell", 50000],
["Mobile", "Samsung", 20000]
],
"Appliances" => [
["Washing Machine", "LG", 30000],
["Refrigerator", "Whirlpool", 25000]
]
];
// Loop के साथ data access करना
foreach ($products as $category => $items) {
echo "Category: $category\n";
foreach ($items as $item) {
foreach ($item as $detail) {
echo $detail . " ";
}
echo "\n";
}
}
?>PHP
Multidimensional Array में Functions का उपयोग:
PHP Multidimensional Array के साथ काम करने के लिए कई built-in functions का उपयोग किया जा सकता है।
| Function | Description | Example |
|---|---|---|
| count() | Array में elements की संख्या गिनता है। | count($students) |
| array_keys() | Array की सभी keys प्राप्त करता है। | array_keys($products) |
| array_merge() | Arrays को merge करता है। | array_merge($array1, $array2) |
| print_r() | Array का readable structure दिखाता है। | print_r($products) |
<?php
$students = [
["Ravi", 85, 90, 78],
["Pooja", 92, 88, 95]
];
// Total rows count करना
echo "Total Rows: " . count($students) . "\n"; // Output: Total Rows: 2
// Array का structure print करना
print_r($students);
?>PHP
Php Multidimensional Array के Practical उपयोग:
Example 1: Students के Marks Store करना
<?php
$students = [
["name" => "Ravi", "Math" => 85, "Science" => 90],
["name" => "Pooja", "Math" => 92, "Science" => 88]
];
foreach ($students as $student) {
echo "Name: " . $student["name"] . "\n";
echo "Math Marks: " . $student["Math"] . "\n";
echo "Science Marks: " . $student["Science"] . "\n";
echo "----------------------\n";
}
?>PHP
Conclusion:
- Php Multidimensional Arrays complex डेटा को store और manage करने का एक structured तरीका प्रदान करते हैं।
- ये डेटा को rows और columns के रूप में represent करने के लिए उपयोगी हैं।
- Loop और built-in functions का उपयोग करके इन Arrays के साथ आसानी से काम किया जा सकता है।

Welcome to HindiTutorials, your go-to platform for learning and mastering concepts in Hindi! Our mission is to make education accessible and simple for everyone by providing high-quality tutorials on programming, technology, and various other topics.