Part 2 · Types / Typed arrays
Lesson 4 of 8

Typed arrays

++PHP distinguishes array<T> lists, array<K, V> maps, and deliberately broad bare array. Element and key types are enforced project-wide:

ids.ppphp
array<int> $ids = [1, 2, 3];
array<string, int> $scores = ['Maya' => 92];

The last line in the editor appends a string to the array<int> list. Press Check and read the diagnostic, then append an int instead:

ids.ppphp
$ids[] = 4;

Check again and the file passes.