Home > Backend Development > PHP Tutorial > switch.case话语调用时间参数程序出错求解决

switch.case话语调用时间参数程序出错求解决

WBOY
Release: 2016-06-13 11:54:50
Original
858 people have browsed it

switch...case语句调用时间参数程序出错求解决。
switch.....case语句以其高利率和高方便性成为我最常用的选择语句,stristr函数大家都知道吧,将这两个结合起来以当前时间做参数写语句是个不错的想法,调试时遇到问题,求解决:
date_default_timezone_set("Asia/ShangHai");
$h=date(" H:i");
 echo $h;//输出当前时间;
switch($h){
  
case "12:00";//可以取任意时间,这里做调试用,随便取的;
            if ($k="12:00");
        if(stristr($k, $h) != "");
echo “成功”;
break;
case "12:01";
if ($k="12:01");
if(stristr($k, $h) != "");
echo "又成功了";
break;
default:
 echo "失败";
}

?>
调试时屡屡出错,请解答,谢了

------解决方案--------------------
你 $h=date(" H:i");
时间前面多了一个空格
所以不会进入形如 case "12:01"; 的任何分支,因为没有前导的空格

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template