当前位置:Gxlcms > PHP教程 > ,值班代码如何写

,值班代码如何写

时间:2021-07-01 10:21:17 帮助过:12人阅读

求助,值班代码怎么写
最近在做单位的网站,基础很薄弱,很多东西都是边看书边百度摸索着做的
最近想要实现在主页上显示每天的值班人员,四天轮一次。
我写的代码如下。
$zbb0=array("张三","李四","王五")
$zbb1=array("张三1","李四1","王五1")
$zbb2=array("张三2","李四2","王五2")
$zbb3=array("张三3","李四3","王五3")
$date_time=getdate(time));
$yday=$date_time["yday"];
if ($yday%4==0){
echo "$zbb0";}
if ($yday%4==1){
echo "$zbb1";}
if ($yday%4==2){
echo "$zbb2";}
if ($yday%4==3){
echo "$zbb3";}
?>
大概意思就是获取当前日期是今年的第几天,再除以四得出余数,根据余数的数值显示相应的人员


------解决方案--------------------
$zbb0=array("张三","李四","王五");
$zbb1=array("张三1","李四1","王五1");
$zbb2=array("张三2","李四2","王五2");
$zbb3=array("张三3","李四3","王五3");
$date_time=getdate(time());
$yday=$date_time["yday"];
$day=$yday%4; //余数

$zb='zbb'.$day; //是哪天的变量
$zbb=$$zb;
print_r($zbb);
------解决方案--------------------
PHP code

array("张三","李四","王五")
,array("张三1","李四1","王五1"),
array("张三2","李四2","王五2"),
array("张三3","李四3","王五3")
);
 
$today=date("N");
 
switch ($today%4)
{
    case 1:
        print_r($zb[1]);
        break;
    case 2:
        print_r($zb[2]);
        break;
    case 3:
        print_r($zb[3]);
        break;
    case 4:
        print_r($zb[3]);
        break;
        
}
?>

------解决方案--------------------
$zbb = array(
array("张三","李四","王五"),
array("张三1","李四1","王五1"),
array("张三2","李四2","王五2"),
array("张三3","李四3","王五3"),
);
print_r($zbb[date('z')%4]);

echo join(',', $zbb[date('z')%4]);

人气教程排行