php switch 语句中不能做判断吗

switch($data['MsgType']){
                case "text" :
                $this->Text($wechat,$data);
                
                case "event":
                if(!$data['EventKey']){
                    $text="没有EVENTKEY";
                    $this->logger("发送消息:\n".$text);
                    $this->Text($wechat,$data);
                }
                
                $this->eventKey($wechat,$data);
            }

这样写了但是判断不出来

阅读 3.9k
1 个回答

每个case结束时要加 break;

switch($data['MsgType']){
    case "text" :
        $this->Text($wechat,$data);
        break;
    case "event":
        if(!$data['EventKey']){
            $text="没有EVENTKEY";
            $this->logger("发送消息:\n".$text);
            $this->Text($wechat,$data);
        }

        $this->eventKey($wechat,$data);
        break;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题