unpacking an array of arguments in php unpacking an array of arguments in php php php

unpacking an array of arguments in php


In php5.6 Argument unpacking via ... (splat operator) has been added. Using it, you can get rid of call_user_func_array() for this simpler alternative. For example having a function:

function add($a, $b){  return $a + $b;}

With your array $list = [4, 6]; (after php5.5 you can declare arrays in this way).

You can call your function with ...:

echo add(...$list);


You can use call_user_func_array() to achieve that:

call_user_func_array("range", $args); to use your example.


In certain scenarios, you might consider using unpacking, which is possible in php, is a similar way to python:

list($min, $max) = [3, 6];range($min, $max);

This is how I have arrived to this answer at least.Google search: PHP argument unpacking