doufu9521 2015-04-07 00:32
浏览 78
已采纳

PHP三元运算符不工作但不显示任何错误

<?php
    /*if(isset($_COOKIE["telcoProvider"])) {
        $telcoProvider = $_COOKIE["telcoProvider"];

    } else {
        $telcoProvider = "NOT FOUND";
    }*/

    $telcoProvider = isset($_COOKIE["telcoProvider"]) ? $_COOKIE["telcoProvider"] : "NOT FOUND".

    print "<p>Your telecommunication company is <b>$telcoProvider.</b></p>";
?>

I have checked the browser and the Cookie is there.

It works with the normal if-else, but not with the ternary operator. It does not proceed to the print, yet, it does not display any error either.

What am I missing?

  • 写回答

1条回答 默认 最新

  • douyou9923 2015-04-07 00:34
    关注
    $telcoProvider = isset($_COOKIE["telcoProvider"]) ?
     $_COOKIE["telcoProvider"] : "NOT FOUND".
                                            ^
    

    What's that dot (.) doing there instead of a ; ?

    I wonder why Eclipse did not say anything?

    Try this and you will get to an answer to that question :) Note the dot before print

    $test= 1==1? "Oh nice no print :P " : "Oh" . print("Really?");
    var_dump($test);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部