PHP 包包含多个不同长度的值
我想打包一个由 64 位、32 位和 32 位整数组成的字符串。 我对 pack 函数(或全部)没有太多经验,所以我尝试做这样的事情:
pack('JNN', 1, 2, 3);
// and
unpack('JNN');
但这并没有产生我想要的结果。
问题是,当我运行该代码时,我收到以下信息:
array [
"NN" => 1
]
但我期望这样:
array [
1,
2,
3
]
知道如何解决这个问题吗?
提前致谢,
I'd like to pack a string consisting of a 64 bits, 32 bits and 32 bits ints.
I don't have much experience with the pack function (or bits altogether) so I'm trying to do something like this:
pack('JNN', 1, 2, 3);
// and
unpack('JNN');
But that does not yield the result I'm after.
The problem is that when I run that code I receive the following:
array [
"NN" => 1
]
But I expected this:
array [
1,
2,
3
]
Any idea how to approach this?
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pack 创建一个 16 个字符的字符串。
unpack 需要格式元素的键。示例:
有关更多示例,请参阅 PHP 手册中的 Unpack。
如果需要纯数字键,可以使用 array_values 函数。
pack creates a 16-character string.
unpack requires keys for the format elements. Example:
For more examples, see Unpack in the PHP manual.
If purely numeric keys are required, the array_values function can be used.