Reverting unpack('C*', “string”)

前端 未结 2 1879
醉梦人生
醉梦人生 2021-01-18 05:22

I would like to know how I can reverse what this unpack function bellow performed. I think the pack function is able to reverse what unpack performed, however I\'m not sure.

相关标签:
2条回答
  • 2021-01-18 06:01

    You should use call_user_func_array to revert unpack('C*', “string”), like this:

    call_user_func_array('pack', array_merge(array('C*'), $array )))
    
    0 讨论(0)
  • 2021-01-18 06:07

    When you're on PHP 5.6, you should consider using argument unpacking as it is about 4 to 5 times faster than using call_user_func_array:

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

    And when you're on PHP 5.5 or lower, you should consider using ReflectionFunction, which seems to be a bit faster than call_user_func_array:

    $packFunction = new ReflectionFunction('pack');
    $packFunction->invokeArgs(array_merge(array('C*'), $array));
    
    0 讨论(0)
提交回复
热议问题