Voting

: four minus zero?
(Example: nine)

The Note You're Voting On

kennwhite dot nospam at hotmail dot com
20 years ago
If having a zero-based index is useful/necessary, then instead of:

$int_list = unpack("s*", $some_binary_data);

try:

$int_list = array_merge(unpack("s*", $some_binary_data));

This will return a 0-based array:

$int_list[0] = x
$int_list[1] = y
$int_list[2] = z
...

rather than the default 1-based array returned from unpack when no key is supplied:

$int_list[1] = x
$int_list[2] = y
$int_list[3] = z
...

It's not used often, but array_merge() with only one parameter will compress a sequentially-ordered numeric-index, starting with an index of [0].

<< Back to user notes page

To Top