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); // 3All lessons in this course
- Indexed and Associative Arrays
- Multidimensional Arrays
- Sorting and Searching Arrays
- Array Transformation Functions