Unpacking¶
Unpacking has two meanings:
unpack(), a PHP native function, which extracts data from a binary string. It has thepack()reverse function.Unpacking arguments, with the
...operator: turning an array into a list of arguments at call time.
<?php
// Unpacking arguments
function foo($a, $b, $c) {
return $a + $b * $c;
}
$arguments = ['a' => 1, 'b' => 2, 'c' => 3];
echo foo(...$arguments);
// display 7
?>