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?
&lt;?php
/ * if(isset($ _ COOKIE [“telcoProvider”])) {
$ telcoProvider = $ _COOKIE [“telcoProvider”];
} else {
$ telcoProvider =“NOT FOUND”;
} * /
$ telcoProvider = isset($ _ COOKIE [“telcoProvider” “])? $ _COOKIE [“telcoProvider”]:“未找到”。
打印“&lt; p&gt;您的电信公司是&lt; b&gt; $ telcoProvider。&lt; / b&gt;&lt; / p&gt;”;
?&gt; ;
code> pre>
我已经检查了浏览器并且Cookie已经存在。 p>
它适用于正常的if-else,但是 不是三元运算符。 它没有进入 print code>,但它也没有显示任何错误。 p>
我缺少什么? p>
div >
答
$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);