I'm having a tough time converting a value I read from socket connection into an integer. It's value tells me how many bytes are going to be received next.
$ar = fread($client, 4);
$binaryInt = unpack('N', $ar);
debug_to_console($binaryInt); //displays 16 (as expected)
$bred = fread($client, intval($binaryInt)); //intval returns 1
For some reason intval always evaluates to 1 and I can't figure out why. Btw the $ar variable is sent an integer from a java server I have running via this code sample
dOut.writeInt(data.length);
Thanks
edit
I finally got it. user2587326 below helped but instead of using intval(binaryInt[1]) it was just binaryInt[1].
I think you are reading a 4-byte integer sent from your Java program over DataOutputStream to your PHP program over socket.
First, the fread($client, 4) call reads those 4 bytes as a string, then you convert them to an array with unpack(), taking 4-bytes at a time (format specifier 'N') thus resulting with an array with one element, so you just use:
intval($binaryInt[1]) instead of intval($binaryInt) to obtain that number.
edit: but it works with intval too, it won't hurt it.