I have seen a code that converts integer into byte array. Below is the code on How to convert integer to byte array in php 3 (How to conver
In order to get a signed 4-byte value in PHP you need to do this:
$temp = ($ar[0]<<24) + ($ar[1]<<16) + ($ar[2]<<8) + ($ar[3]);
if($temp > 2147483648)
$temp -= 4294967296;
Why not treat it like the math problem it is?
$i = ($ar[3]<<24) + ($ar[2]<<16) + ($ar[1]<<8) + $ar[0];
Since L is four bytes long, you know the number of elements of the array. Therefore you can simply perform the operation is reverse:
$ar = [64,226,1,0];
$i = unpack("L",pack("C*",$ar[3],$ar[2],$ar[1],$ar[0]));