📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

6. Arrays (PHP)

Arrays in PHP are used to store multiple values in a single variable instead of creating separate variables.

👉 Example:

$fruits = ["Apple", "Banana", "Mango"];

🔹 1. Indexed Arrays

These arrays use numeric indexes (0, 1, 2…)

✅ Example:

$colors = ["Red", "Green", "Blue"];echo $colors[0]; // Red
echo $colors[1]; // Green

✅ Using loop:

for ($i = 0; $i < count($colors); $i++) {
echo $colors[$i] . "<br>";
}

👉 Best for: lists of items


🔹 2. Associative Arrays

These arrays use named keys instead of numbers

✅ Example:

$student = [
"name" => "Aditya",
"age" => 22,
"course" => "BCA"
];echo $student["name"]; // Aditya

✅ Loop:

foreach ($student as $key => $value) {
echo "$key: $value <br>";
}

👉 Best for: structured data (like objects)


🔹 3. Multidimensional Arrays

Arrays inside arrays (used for complex data)

✅ Example:

$students = [
["Aditya", 22, "BCA"],
["Rahul", 21, "BSc"],
["Neha", 23, "MCA"]
];echo $students[0][0]; // Aditya
echo $students[1][2]; // BSc

✅ Loop:

foreach ($students as $student) {
echo $student[0] . " - " . $student[2] . "<br>";
}

👉 Best for: tables / database-like data


🔹 4. Important Array Functions

✅ 1. sort() → Sort values (ascending)

$numbers = [3, 1, 5, 2];
sort($numbers);
print_r($numbers);

✅ 2. rsort() → Descending sort

rsort($numbers);

✅ 3. asort() → Sort associative array by value

$age = ["Aditya" => 22, "Rahul" => 20];
asort($age);

✅ 4. ksort() → Sort by key

ksort($age);

✅ 5. array_merge() → Combine arrays

$a = ["Red", "Blue"];
$b = ["Green", "Yellow"];$result = array_merge($a, $b);
print_r($result);

✅ 6. array_filter() → Filter values

$numbers = [1, 2, 3, 4, 5];$even = array_filter($numbers, function($n) {
return $n % 2 == 0;
});print_r($even);

✅ 7. array_map() → Modify each value

$numbers = [1, 2, 3];$square = array_map(function($n) {
return $n * $n;
}, $numbers);print_r($square);

🎯 Summary

TypeUse Case
Indexed ArraySimple lists
Associative ArrayKey-value data
Multidimensional ArrayComplex/nested data

💡 Teaching Tip (for your students)

Explain like this:

  • Indexed = List 📋
  • Associative = Dictionary 📖
  • Multidimensional = Table 📊


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes