对于一个有趣的项目,我想在PHP中创建一个二进制时钟,所以基本上为了简单起见,我使用date("H:m:s");
来获取字符串格式的时间,然后使用str_split();
将每个字符串字母分成一个数组。
我的代码可以使用它:
$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),
);
无论我是否尝试这两个来解决问题,结果数组例如如下(为清晰起见,旁边有小数):
10000000 -> 128
10000000 -> 128
10000000 -> 128
00000000 -> 0
10000000 -> 128
10010000 -> 144
为什么那些不是1-9的二进制文件?