dsdfd2322 2015-12-01 23:01
浏览 30

在PHP中,三元和If语句之间的执行逻辑区别是什么?

I don't know what I am missing! I have the following code

//does not work
$arg = (isset($_REQUEST['TEST']))? $_REQUEST['TEST'] : $_REQUEST['test'];

// While this works
if(isset($_REQUEST['TEST'])){ $arg = $_REQUEST['TEST']; }
if(isset($_REQUEST['test'])){ $arg = $_REQUEST['test']; }

Is there a difference in how each conditional handle the above code? It reads the same to me! any explanation?

P.S

There should not be a difference ! Is there a global PHP setting that could affect this?

  • 写回答

1条回答 默认 最新

  • doujia1939 2015-12-01 23:09
    关注

    I do not think there is any functional difference between the two

    $arg = (isset($_REQUEST['TEST']))? $_REQUEST['TEST'] : $_REQUEST['test'];
    

    are you sure $_REQUEST['test'] exists and has a value ? Because in your second statement

     if(isset($_REQUEST['test']))
    

    you are explicitly checking its value but in the first statement you are not.

    评论

报告相同问题?

悬赏问题

  • ¥15 在matlab中Application Compiler后的软件无法打开
  • ¥15 想问一下STM32创建工程模板时遇到得问题
  • ¥15 Fiddler抓包443
  • ¥20 Qt Quick Android 项目报错及显示问题
  • ¥15 而且都没有 OpenCVConfig.cmake文件我是不是需要安装opencv,如何解决?
  • ¥15 oracleBIEE analytics
  • ¥15 H.264选择性加密例程
  • ¥50 windows的SFTP服务器如何能批量同步用户信息?
  • ¥15 centos7.9升级python3.0的问题
  • ¥15 安装CentOS6时卡住