New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials PHP PHP Arrays

PHP Arrays

PHP

Arrays store multiple values in a single variable. PHP has two types:

  • Indexed arrays — numbered keys (0, 1, 2...)
  • Associative arrays — named keys ("name", "age"...)

Arrays are the most used data structure in PHP. Master them!

Example — PHP
<?php
// Indexed array
$colors = ["Red", "Green", "Blue"];
echo $colors[0]; // Red
echo "<br>";
echo "Total colors: " . count($colors);

echo "<br><br>";

// Associative array
$student = [
    "name" => "Priya",
    "age" => 16,
    "class" => "10th",
    "marks" => 92
];

echo "Name: " . $student["name"] . "<br>";
echo "Class: " . $student["class"] . "<br>";
echo "Marks: " . $student["marks"] . "%";
?>
Result
Red
Total colors: 3

Name: Priya
Class: 10th
Marks: 92%