OnlineCBT Logo OnlineCBT
PHP · LESSON 8

Indexed, Associative, and Multidimensional Arrays

By Ratan Updated: 16 Oct 2026

Store ordered lists, key-value associative maps, and nested arrays in PHP.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. Understanding Arrays in PHP

An array is an ordered data structure that stores multiple values within a single variable. PHP supports three primary array formats:

2. Indexed Arrays

Indexed arrays use numeric indices starting from 0:

";
}

3. Associative Arrays

Associative arrays use named keys (strings) to access stored values:

 "Priya Sharma",
    "email" => "priya@example.com",
    "course" => "NEET Preparation",
    "isActive" => true
];

echo $student["name"]; // Priya Sharma

// Adding a new key-value pair
$student["enrollment_year"] = 2026;

// Iterating key and value pairs
foreach ($student as $key => $val) {
    echo ucfirst($key) . ": " . (is_bool($val) ? ($val ? 'Yes' : 'No') : $val) . "
"; }

4. Multidimensional Arrays

A multidimensional array is an array containing one or more arrays. They are commonly used to represent database records or matrix grids:

 1, "name" => "Aarav", "score" => 98],
    ["rank" => 2, "name" => "Sneha", "score" => 95],
    ["rank" => 3, "name" => "Rohan", "score" => 91],
];

// Accessing Sneha's score:
echo $examLeaderboard[1]["score"]; // 95

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat