Last active
March 14, 2019 03:54
-
-
Save guanguans/5484052b43e9e30cdc84ddf1705794bd to your computer and use it in GitHub Desktop.
位运算表示状态
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getHourInt($timeArray) | |
{ | |
$val = 0; | |
for ($i = 0; $i <= 23; $i++) { | |
if (in_array($i . '', $timeArray)) { | |
$val |= pow(2, $i + 1); | |
} | |
} | |
return $val; | |
} | |
function getHourArray($hour) | |
{ | |
$val = []; | |
for ($i = 0; $i <= 23; $i++) { | |
if (($hour & pow(2, $i + 1)) > 0) { | |
$val[] = $i; | |
} | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment