Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何将一天分为三班_Php - Fatal编程技术网

PHP-如何将一天分为三班

PHP-如何将一天分为三班,php,Php,我有一个数据库,可以保存物品的生产时间。因为某些原因,我不能分三班 在我的代码(php)中,我首先得到生产的小时数($rest)(从00到23),然后我尝试使用if函数根据$rest来表示是A、B还是C移位 这是我的密码: $rest = substr("$time", -8, 2); if ($rest > 06 or $rest < 15) { $shift = "A"} if ($rest > 14 or $rest < 23) { $shift =

我有一个数据库,可以保存物品的生产时间。因为某些原因,我不能分三班

在我的代码(php)中,我首先得到生产的小时数($rest)(从00到23),然后我尝试使用if函数根据$rest来表示是A、B还是C移位

这是我的密码:

$rest = substr("$time", -8, 2);
if ($rest > 06 or $rest < 15) {
    $shift = "A"}
if ($rest > 14 or $rest < 23) {
    $shift = "B"}
if ($rest > 22 or $rest < 07) {
    $shift = "C"}
$rest=substr(“$time”,-8,2);
如果($rest>06或$rest<15){
$shift=“A”}
如果($rest>14或$rest<23){
$shift=“B”}
如果($rest>22或$rest<07){
$shift=“C”}
有人能告诉我怎么了吗


提前感谢。

您可以为
切换

$rest = substr($time, -8, 2);
if ($rest > 06 && $rest < 15) {
    $shift ="A";
} else if ($rest > 14 && $rest < 23) {
    $shift ="B";
} else {
    $shift ="C";
}
$rest=substr($time,-8,2);
如果($rest>06&$rest<15){
$shift=“A”;
}如果($rest>14&$rest<23),则为其他情况{
$shift=“B”;
}否则{
$shift=“C”;
}

好的,我终于得到了正确的结果。方法是使用下一个代码:

$rest = substr($time, -8, 2);
if ($rest >= 00){
 $shift ="C";}{
if ($rest > 06){
 $shift ="A";}{
if ($rest >14){
 $shift ="B"}
if ($rest>22){
$shift ="C";}}

对于前两个
IF
语句,您可能希望使用
而不是
。您可能需要使用
IF/ELSE IF/ELSE
而不是3个IF。
$time
的示例值是多少?您也使用八进制数-您知道吗$time=“h:m:s”就像。。比如11:46:34@马修:是的,我知道,但我不能忽视它,因为它没有改变结果。我需要隔一段时间分开。。A=07至15,B=15至23,C=23至07@Mestre1966:我知道,你需要什么,这段代码就是这么做的。你在下面的答案中有什么,它和我的问题相似,只是在更糟糕和更慢的包装中。