Shift with red gradient lettering
Loading navigation...

Array Functions

PHP

Adopt array functions like array_key_first, array_key_last, and is_countable, as well as streamline code to use other native PHP array functions.

Before

reset($items)
$firstKey = key($items);
end($items);
$lastKey = key($items);
 
is_array($foo) || $foo instanceof Countable;
 
$keys = array_keys($values);
$exists = in_array($packageName, $keys, true);
 
array_search("foo", $array) !== false;
 
foreach ($values as $key => $value) {
$items[$key] = null;
}

After

$firstKey = array_key_first($items);
$lastKey = array_key_last($items);
 
is_countable($foo);
 
$exists = array_key_exists($packageName, $values);
 
in_array("foo", $array);
 
foreach (array_keys($values) as $key) {
$items[$key] = null;
}

← Back to the Workbench Tasks