Skip to content

Instantly share code, notes, and snippets.

@guanguans
Last active March 14, 2019 03:54
Show Gist options
  • Save guanguans/5484052b43e9e30cdc84ddf1705794bd to your computer and use it in GitHub Desktop.
Save guanguans/5484052b43e9e30cdc84ddf1705794bd to your computer and use it in GitHub Desktop.
位运算表示状态
<?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