duandan4680 2017-11-10 09:33
浏览 32
已采纳

PHP空变量内部条件

I have a condition in which it is using a variable to pull either a number through 0-17, the string "MAKEUP", or the variable will be empty. I would like it to output the text "WIN" if the variable is greater than the number 8 and "LOSS" if the variable is less than the number 9. I would also like it to out "MAKEUP" if the variable consist of the string MAKEUP, and to display nothing if the variable is empty. Seems pretty simple to me, but I'm having issues particularly with the empty part. Can anyone let me know what I am doing wrong here? Code below

    <?php
    $t1w8 = '';
    $result = $t1w8;
    if ($result > 8 && !empty($result)) {
        echo 'WON';
    } elseif ($result < 9 && !empty($result)) {
        echo 'LOSS';
    } elseif ($result == 'MAKEUP') {
        echo '-';
    } else {
        echo 'yooo';
    }
    ?>
  • 写回答

3条回答 默认 最新

  • doujie9252 2017-11-10 09:42
    关注

    Make some changes in your conditions like this

    <?php
        //$result = "MAKEUP";
        $result = 0;
        if ($result === 'MAKEUP') {
            echo '-';
        }else if (is_numeric($result) && $result < 9 ) {
            echo 'LOSS';
        }else if (is_numeric($result) && $result >= 9 ) {
            echo 'WON';
        } else{
            echo 'yooo';
        }
    ?>
    

    Live demo : https://eval.in/897120

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启