PHP: Cannot cast string to int?

encossisa

New Member
For a fun project I wanted to make a binary clock in PHP, so basically for simplicity's sake I used \[code\]date("H:m:s");\[/code\] to get the time in string format, then used \[code\]str_split();\[/code\] to separate each string letter into an array.My code is here to work with it:\[code\]$time = str_split($time);//I tried $time = array_map(intval, $time); here but no dice$tarray = Array( //hh:mm:ss = [0][1][3][4][6][7] str_pad(decbin((int)$time[0]), 8, STR_PAD_LEFT), //I tried casting to (int) as well str_pad(decbin($time[1]), 8, STR_PAD_LEFT), str_pad(decbin($time[3]), 8, STR_PAD_LEFT), str_pad(decbin($time[4]), 8, STR_PAD_LEFT), str_pad(decbin($time[6]), 8, STR_PAD_LEFT), str_pad(decbin($time[7]), 8, STR_PAD_LEFT),);\[/code\]No matter if I try those two to fix the problem, the resulting array is for example the following (with decimal next to it for clarity):\[code\]10000000 -> 12810000000 -> 12810000000 -> 12800000000 -> 010000000 -> 12810010000 -> 144\[/code\]Why are those not 1-9 in binary?
 
Back
Top