4

I need help with PHP, I need to define byte array and to 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 ?

2

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

Comments

2
$myarray = array(1,2,16,29,33,46,69);

is this an array of byte?

Comments

2

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.