Search code examples
phpargumentspack

Passing an Array as Arguments NOT user function, in PHP


I have the following code:

$bin = "\x04\x00\xa0\x00\x04\x00\xa0\x00";
$unpack_data = unpack("C*", $bin);
$arr = array($unpack_data[1], $unpack_data[2], $unpack_data[3]);

How can I pass an array $arr to a pack() function? The only thing that I can make:

$res = pack("C*", $unpack_data[1], $unpack_data[2], $unpack_data[3]);

but the length and content of the array are getting in the course of the program.


Solution

  • Like this:

    call_user_func_array('pack', array_merge(['C*'], $unpack_data))