How to define array of bytes in PHP
I need help with PHP, I need to define byte array and t开发者_开发百科o change values of some bytes ( for example set 3rd byte to 16 or 17 and so on ). How to define array of bytes in PHP ?
I am not entirely sure what you mean when you say byte. But try this:
<?php
$bytes = array(1, 50, 39, 21, 93, 20);
$bytes[2] = 16; // Changes 3rd byte to 16
$myarray = array(1,2,16,29,33,46,69);
is this an array of byte?
You can define array easily like this:
$bytes = array(1,10,6,67);
change third element:
$bytes[2] = 5;
But be careful! If you delete element 1 (which is 10 in above example):
unset($bytes[1]);
the array will look like this:
array(1,5,67);
however 5 is still element at index 2
echo $bytes[0]; // this will output 1
echo $bytes[2]; // this will output 5
So to change the third element now you have to do this:
$bytes[3] = 123; // because array keys don't change and the third element is now $bytes[3] and not $bytes[2]
精彩评论