简体   繁体   English

如何在PHP中将4字节数组转换为整数?

[英]How to Convert 4-Byte Array to Integer in php?

How to Converts a 4-Byte Array to Integer array. 如何将4字节数组转换为整数数组。

<?php
$i = "A\0\0\0\A\0\0\0\A\0\0\0";  //I think this input 12Byte Array
$j = unpack("i*",$i); //I want this output 65,65,65 (4Byte * 3)
?>

is not working code.. 不工作代码..

how can i get the output 我怎样才能得到输出

   $j[0]=65, $j[1]=65, $j[2]=65 ?

The above code is not working due to the fact that you're trying to reference a variable that wasn't defined: 由于您尝试引用未定义的变量,上面的代码无法正常工作:

$i = "A\0\0\0\A\0\0\0\A\0\0\0"; 
$j = unpack("i*",$i); //$i here, not $j

The output that comes from this is: 来自此的输出是:

Array
(
    [1] => 65
    [2] => 16732
    [3] => 4283392
)

Example/Demo 实施例/演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM