0PricingLogin
PHP Academy · Lesson

Indexed and Associative Arrays

Create and access both types of PHP arrays.

Arrays in PHP

PHP arrays are ordered maps — they can act as lists, dictionaries, stacks, and queues. Two main flavors:

  • Indexed arrays — numeric keys (0, 1, 2…)
  • Associative arrays — string keys

Creating Indexed Arrays

Use the short array syntax [] or array():

<?php
$colors = ['red', 'green', 'blue'];    // short syntax
$nums   = array(10, 20, 30);            // long syntax

echo $colors[0]; // red
echo $nums[2];   // 30
echo count($colors); // 3

All lessons in this course

  1. Indexed and Associative Arrays
  2. Multidimensional Arrays
  3. Sorting and Searching Arrays
  4. Array Transformation Functions
← Back to PHP Academy