Home >Backend Development >PHP Tutorial >,值班代码如何写

,值班代码如何写

WBOY
WBOYOriginal
2016-06-13 10:06:431435browse

求助,值班代码怎么写
最近在做单位的网站,基础很薄弱,很多东西都是边看书边百度摸索着做的
最近想要实现在主页上显示每天的值班人员,四天轮一次。
我写的代码如下。
$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
$zb=array(1=>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;        }?><br><font color="#e78608">------解决方案--------------------</font><br>$zbb = array(<br> array("张三","李四","王五"),<br> array("张三1","李四1","王五1"),<br> array("张三2","李四2","王五2"),<br> array("张三3","李四3","王五3"),<br>);<br>print_r($zbb[date('z')%4]);<br>或<br>echo join(',', $zbb[date('z')%4]);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn