Antrikssh Posted September 21, 2012 Share Posted September 21, 2012 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 More sharing options...
kanchatchai Posted September 21, 2012 Share Posted September 21, 2012 <?php$SrcArry = array(10,20,30,40,50);$DestArry = array();$Str = NULL;for ($i = 0;$i < 5;$i++) {$Str .= pack('I', $ScrArry[$i]);} Link to comment Share on other sites More sharing options...
Ingolme Posted September 21, 2012 Share Posted September 21, 2012 That's probably because NULL is a byte of some sort. You probably should initialize $Str as an empty string: $Str = ''; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now