tags:

views:

92

answers:

1

I have code JAVA

byte abyte1[] = new byte[k];

But php not have byte type. Its possible to convert this line to php?

+6  A: 

The concept of a fixed-length array is not really one that exists in php. Additonally, you don't specify the type of an array either, instead all arrays are actually a hash, that can store any type.

The closest thing to what you ask is:

$abyte1 = array();

And then you can just insert bytes as you might normally:

$abyte1[0] = 1;
$abyte1[1] = 2;

Or you can add to the end of the list:

$abyte1[] = 3;
Kazar
As of PHP5.3, PHP does have Fixed Length Arrays through SplFixedArray http://us.php.net/manual/en/class.splfixedarray.php
Gordon
@Gordon, duly noted, however the comments at the bottom of the page suggest only marginal performance gains for small sets of data. Additionally, as you said, it is only in 5.3.
Kazar