ollie007 Posted June 7, 2009 Share Posted June 7, 2009 what does " $var ? $var : ' ' " mean? check var from var, default '' where can i learn more about it? Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/ Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 That is a shorthand way of writing an if statement.. http://www.tech-recipes.com/rx/288/php-if-statement-syntax/ http://www.scottklarr.com/topic/446/shorthand-php-if-statement-without-the-else-notation/ $variable = (statement) ? "return if true" : "return if false"; //# Compared to if(statement) { $variable = "return this if true"; } else { $variable = "return this if false"; } Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/#findComment-850859 Share on other sites More sharing options...
alco19357 Posted June 7, 2009 Share Posted June 7, 2009 $var ? $var : ' ' if $var is set, then echo $var, else echo ' ' you would need an echo in front of $var though Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/#findComment-850862 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 It's called a ternary statement. alco19357, that's not exactly true. It's not so much if $var is set, but more like if (bool) $var is true. It doesn't exactly echo. It really depends on what's before the ternary statement in that line. Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/#findComment-850863 Share on other sites More sharing options...
ollie007 Posted June 7, 2009 Author Share Posted June 7, 2009 ty all !! and yes it came from an isset statemet but i wanted to learn the basics Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/#findComment-850889 Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 Welcome to the PHP family, an everlasting quest of finding new ways to make computers do your bidding Link to comment https://forums.phpfreaks.com/topic/161250-explain-php-syntax/#findComment-850905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.