PHP将数组传递给pack()函数 [英] PHP Passing an array to pack() function
本文介绍了PHP将数组传递给pack()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pack()
语法是(来自 http://php.net/manual/zh/function.pack.php )
string pack ( string $format [, mixed $args [, mixed $... ]] )
所以假设我需要打包三个字节
so assuming I need to pack three bytes
$packed = pack( "c*", 65, 66, 67 );
但是如果我必须打包任意数量的字节怎么办?
But what if I have to pack an arbitrary number of bytes?
可以方便地将它们存储到数组中,所以我天真地尝试过
They could coveniently be stored into an array so I naively tried
$a = array( 65, 66, 67 );
$packed = pack( "c*", $a );
但这是行不通的.
有没有办法使pack()
与数组一起工作?
Is there a way to make pack()
work with an array ?
推荐答案
晚了一点,但是为了将来参考,您可以使用新的...
运算符(v5.6 +)来内联分解数组:
At little late to the party, but for future reference, you can use the new ...
operator (v5.6+) to explode the array inline:
$packed = pack("c*", ...$a);
这篇关于PHP将数组传递给pack()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文