array_filter with ARRAY_FILTER_USE_KEY, from 5.6

array_filter() has always passed the value to the callback and never the key, so filtering an associative array by its keys meant building the predicate out of three other functions. PHP 5.6, released at the end of August, adds a mode argument that lets the callback receive the key instead — or both.

$config = array(
    'db_host'   => 'localhost',
    'db_name'   => 'catalogue',
    'mail_host' => 'smtp.internal',
);

// 5.6
$db = array_filter($config, function ($key) {
    return strpos($key, 'db_') === 0;
}, ARRAY_FILTER_USE_KEY);

// before 5.6, the same predicate, three calls deep
$db = array_intersect_key($config, array_flip(array_filter(array_keys($config), function ($key) {
    return strpos($key, 'db_') === 0;
})));

// both, when the decision needs the pair
array_filter($rows, function ($value, $key) {
    return $value > 0 && substr($key, 0, 1) !== '_';
}, ARRAY_FILTER_USE_BOTH);

The old form is not wrong, it is just unreadable in a way that hides the actual condition three levels inside a call. Two details survive the change. array_filter() preserves keys in every mode, so filtering a numerically indexed list leaves gaps and anything treating the result as a list needs array_values(). And the mode is the third argument rather than something the callback declares, so writing a two-parameter callback and forgetting ARRAY_FILTER_USE_BOTH produces a missing-argument warning per element rather than an obvious failure. On a server still running 5.5 the constant does not exist at all, which makes this one of the easier things to guard behind a version check while a fleet is being upgraded.