PHP-如何将一天分为三班
我有一个数据库,可以保存物品的生产时间。因为某些原因,我不能分三班 在我的代码(php)中,我首先得到生产的小时数($rest)(从00到23),然后我尝试使用if函数根据$rest来表示是A、B还是C移位 这是我的密码: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 =
$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:我知道,你需要什么,这段代码就是这么做的。你在下面的答案中有什么,它和我的问题相似,只是在更糟糕和更慢的包装中。