haphpiness

These are things in PHP which make me genuinely_happy();

array_find(), array_any(), array_all()

PHP 8.4 added the array search and predicate functions that every developer has been writing by hand for years. No more array_filter + count hacks or manual loops just to answer "is there any?" or "do all match?"

$users = [
    ['name' => 'Alice', 'role' => 'admin'],
    ['name' => 'Bob', 'role' => 'editor'],
    ['name' => 'Charlie', 'role' => 'viewer'],
];

// Find the first match
$admin = array_find($users, fn($u) => $u['role'] === 'admin');
// ['name' => 'Alice', 'role' => 'admin']

// Find the key of the first match
$key = array_find_key($users, fn($u) => $u['role'] === 'editor');
// 1

// Does ANY element match?
$hasAdmin = array_any($users, fn($u) => $u['role'] === 'admin');
// true

// Do ALL elements match?
$allViewers = array_all($users, fn($u) => $u['role'] === 'viewer');
// false

// Short-circuits — stops as soon as the answer is known
$found = array_any($hugeArray, fn($item) => $item->isExpired());
// Stops at the first expired item, doesn't scan the rest

These functions accept callbacks, short-circuit when possible, and work with keys as well as values. They complement phparray_filter, phparray_map, and phparray_reduce to form a complete functional array toolkit.

Significance: Expressiveness

"Find the first X" and "do any/all match?" are among the most common array operations in any codebase. Dedicated functions for these patterns replace hand-rolled loops, make intent explicit, and short-circuit for performance — the standard library doing what a standard library should.