array_push()
and
array_unshift()
array_push()
and array_unshift()
can
now also be called with a single argument:
$array = [];
array_push($array);
array_unshift($array);
var_dump($array);
Executing the code shown above will print the output shown below:
array(0) {
}
Being able to call array_push()
and
array_unshift()
with only a single argument is useful
when the spread operator ...
is used as
...$values
may be unpacked to an empty list in which
case array_push($array, ...$values)
, for instance,
leads to array_push()
being called with only
$array
as argument.