PHP Indexed Array एक ऐसा array होता है जिसमें values को numerical index (यानी संख्या) के साथ store किया जाता है। इन Arrays का index 0 से शुरू होता है। Indexed Arrays का उपयोग तब किया जाता है जब data को क्रमबद्ध तरीके से संग्रहीत करना हो, जैसे items की list या numbers की series.
Php Indexed Array के Features:
- Data को sequential order (क्रमबद्ध) में store करता है।
- Index हमेशा 0 से शुरू होता है।
- Elements को index के जरिए access किया जाता है।
- हर value के लिए index अपने-आप assign हो जाता है।
Php Indexed Array को Define करने के तरीके:
PHP में Indexed Array को दो तरीकों से define किया जा सकता है:
- Traditional Syntax (array() function)
- Short Syntax ([])
Example:
<?php
// Traditional तरीके से
$fruits = array("Apple", "Banana", "Mango");
// Short सिंटैक्स से
$fruits = ["Apple", "Banana", "Mango"];
?>PHPIndexed Array में Value को Access करना:
Indexed Array के elements को उनके index number से access किया जाता है। Index 0 से शुरू होता है।
<?php
$fruits = ["Apple", "Banana", "Mango"];
echo $fruits[0]; // Output: Apple
echo $fruits[1]; // Output: Banana
echo $fruits[2]; // Output: Mango
?>PHPIndexed Array को Loop से Access करना:
PHP में loop का उपयोग करके Indexed Array के सभी elements को आसानी से access किया जा सकता है।
Using for Loop:
<?php
$fruits = ["Apple", "Banana", "Mango"];
for ($i = 0; $i < count($fruits); $i++) {
echo $fruits[$i] . "\n";
}
?>PHP
Using foreach Loop:
<?php
$fruits = ["Apple", "Banana", "Mango"];
foreach ($fruits as $fruit) {
echo $fruit . "\n";
}
?>PHP
Indexed Array में Dynamically Value Add करना:
आप किसी भी Indexed Array में नई value dynamically जोड़ सकते हैं।
<?php
$fruits = []; // Empty Array
$fruits[] = "Apple"; // Index 0 पर value add की
$fruits[] = "Banana"; // Index 1 पर value add की
$fruits[] = "Mango"; // Index 2 पर value add की
print_r($fruits);
?>PHP
Indexed Array में Functions का Use:
PHP में array के साथ कई built-in functions होते हैं। Php Indexed Array के साथ commonly use किए जाने वाले कुछ functions हैं:
| Function | Description | Example |
|---|---|---|
| count() | Array में elements की संख्या return करता है | count($fruits) |
| sort() | Array को ascending order में sort करता है | sort($numbers) |
| rsort() | Array को descending order में sort करता है | rsort($numbers) |
| array_push() | Array में नई value जोड़ता है | array_push($fruits, “Grapes”) |
| array_pop() | Array के last element को हटाता है | array_pop($fruits) |
Example:
<?php
$numbers = [5, 3, 8, 1];
// Total elements count
echo count($numbers); // Output: 4
// Array को sort करना
sort($numbers);
print_r($numbers);
/* Output:
Array (
[0] => 1
[1] => 3
[2] => 5
[3] => 8
)*/
?>PHPIndexed Array के Errors और उनका Solution:
Undefined Index Error:
जब आप Array के ऐसे index को access करते हैं जो exist नहीं करता, तो PHP “Undefined Index” error देता है।
Solution: isset() Function का उपयोग करके हम इस Error को रिमूव कर सकते हैं।
<?php
$fruits = ["Apple", "Banana"];
if (isset($fruits[2])) {
echo $fruits[2];
} else {
echo "Index 2 का element exist नहीं करता।";
}
?>PHPConclusion:
- Indexed Arrays sequential data को store और manage करने के लिए उपयोग किए जाते हैं।
- Loop और functions का उपयोग करके हम Arrays के elements को आसानी से access और manipulate कर सकते हैं।
- Indexed Array data को organize और readable बनाने का एक आसान तरीका है।

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.