Mr.Shawn Posted February 9, 2008 Share Posted February 9, 2008 $requested = empty($_SERVER['REQUEST_URI']) ? false : $_SERVER['REQUEST_URI']; What does the above code means? What's with the ? and : Link to comment https://forums.phpfreaks.com/topic/90171-dont-understand-this-code/ Share on other sites More sharing options...
rlindauer Posted February 9, 2008 Share Posted February 9, 2008 Look up the ternary operator. http://us3.php.net/language.operators.comparison Link to comment https://forums.phpfreaks.com/topic/90171-dont-understand-this-code/#findComment-462378 Share on other sites More sharing options...
phpknight Posted February 9, 2008 Share Posted February 9, 2008 It means if that if $_SERVER['REQUEST_URI'] is not set, then $requested is false. Otherwise, it is set to its value. ? : is an easy way to do quick if/else syntax $value=($number<0)? "negative": "positive"; If the condition in (here) is true, the $value gets set to the first value. If not, it's the second one. Of course zero is not really positive, but you get the point. Link to comment https://forums.phpfreaks.com/topic/90171-dont-understand-this-code/#findComment-462380 Share on other sites More sharing options...
Mr.Shawn Posted February 16, 2008 Author Share Posted February 16, 2008 Well explained. Thank you so much. Link to comment https://forums.phpfreaks.com/topic/90171-dont-understand-this-code/#findComment-468200 Share on other sites More sharing options...
phpSensei Posted February 16, 2008 Share Posted February 16, 2008 you know what, this is how i understood it first $var = ($var == "a") ? "the var $var is now this string" : "If the var does not equal A, then the $var is equalled to this string"; Link to comment https://forums.phpfreaks.com/topic/90171-dont-understand-this-code/#findComment-468201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.