The PHP array functions worth memorising

Short answer

Learn array_map, array_filter, array_reduce, array_column, in_array, array_keys, array_values, usort, array_slice, array_merge, implode and count. Between them they cover most day-to-day array work.

php
$videos = [
    ['title' => 'Intro to Python', 'views' => 197, 'track' => 'python'],
    ['title' => 'PHP Web Form',    'views' => 259, 'track' => 'php'],
    ['title' => 'Racket Install',  'views' => 696, 'track' => 'racket'],
];

#Transform

php
$titles = array_map(fn($v) => $v['title'], $videos);
$titles = array_column($videos, 'title');            // same, purpose-built
$byId   = array_column($videos, null, 'track');      // key an array by a field

array_column is the one people miss. It extracts one field from every row, and with a third argument it re-keys the whole array.

#Filter

php
$popular = array_filter($videos, fn($v) => $v['views'] > 200);

#Reduce

php
$total = array_reduce($videos, fn($sum, $v) => $sum + $v['views'], 0);
$total = array_sum(array_column($videos, 'views'));   // clearer here

#Sort

php
usort($videos, fn($a, $b) => $b['views'] <=> $a['views']);   // descending

The spaceship operator <=> returns -1, 0 or 1 — exactly what a comparator needs. Note usort sorts in place and returns true, not the sorted array.

php
in_array('php', $tracks, true);          // always pass true for strict compare
array_search('php', $tracks);            // returns the key, or false
array_key_exists('title', $video);

Without the strict flag, in_array(0, ['a','b']) was historically true. Modern PHP fixed the worst cases, but strict comparison is still the correct default.