Skip to content

Chapter 10 of 38

Arrays

Master indexed, associative, multidimensional, transformational, and sorting operations.

42 minutes 10 quick checksBy Subha Prasad
Lesson 10 of 38Course navigation

Lesson content

Read, practise, then check your understanding

PHP arrays are ordered maps with integer or string keys. They can represent lists, dictionaries, and nested records, though arbitrary nested arrays provide weaker contracts than value objects.

Practical example

<?php
$scores = ['Mira' => 91, 'Ari' => 76];
$passing = array_filter($scores, fn(int $score): bool => $score >= 80);
$curved = array_map(fn(int $score): int => min(100, $score + 5), $scores);

Use array_key_exists when null still counts; isset returns false for null. Use strict in_array/array_search. Merge/spread and sorting functions treat keys differently, so select operations deliberately and document expected shapes.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes indexed array?
Which PHP term matches this description: An ordered map commonly keyed by consecutive integers.
Which statement best describes associative array?
Which PHP term matches this description: An ordered map using meaningful string or integer keys.
Which statement best describes multidimensional array?
Which PHP term matches this description: An array containing nested arrays.
Which statement best describes array_map?
Which PHP term matches this description: A function transforming elements through a callback.
Which statement best describes array_filter?
Which PHP term matches this description: A function retaining elements accepted by a callback.

0 of 10 checks passed

Your progress is saved on this device.