Jump to content

Index of array changed during unpack the binary string.


Antrikssh

Recommended Posts

Hello, I worked on pack, unpack function of php. I made a simple test by using pack and unpack function. I worte a simple code like <?php $SrcArry = array(10,20,30,40,50); $DestArry = array(); $Str = NULL; for ($i = 0;$i < 5;$i++) { $Str .= pack('I', $ScrArry[$i]); } $DestArry = unpack('I*',$Str); var_dump($SrcArry); var_dump($DestArry);?> I named this file MyTest.php. Now when I execute this file by using php MyTest.php I got the result like Result of var_dump($ScrArry) array(5) { [0]=> int(10) [1]=> int(20) [2]=> int(30) [3]=> int(40) [4]=> int(50) Result of var_dump($DestArry) array(5) { [1]=> int(10) [2]=> int(20) [3]=> int(30) [4]=> int(40) [5]=> int(50)} My question is this why index of array changed during pack unpack function like [0] => 10 in $ScrArry and[1] => 10 in $DestArry.When I assign source array in destionation array by using $SrcArry = $DestArry (without using pack/unpack) then my indexing of array is correct. Thanks and Regards,Antrikssh...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...