1

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.

3 Answers 3

3

Like this:

call_user_func_array('pack', array_merge(['C*'], $unpack_data))
Sign up to request clarification or add additional context in comments.

Comments

2

New php 5.6 syntax allow this

pack('C*', ...$unpack_data);

Comments

0
$res = pack('C*',$arr)

//hope this might help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.