vr4lyfe Posted July 7, 2006 Share Posted July 7, 2006 Hi guys. I am readying some PHP code and it is using this syntax.$x->var = $ x ? 0 : $ x;I know what most its supposed to do (kinda), but just confused about exact syntax of the "?" and ":" notations.Tried searching PHP.net but couldnt find what I was looking for. Any expect care to point me to a page I can read or explain this to me? Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/ Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 If I'm not wrong, you are using [b]Concise Conditional[/b].There's an example over http://www.cwhnetworks.com/forums/index.php?showtopic=3243 if you are interested. Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54245 Share on other sites More sharing options...
vr4lyfe Posted July 7, 2006 Author Share Posted July 7, 2006 Thanks for the quick reply. I googled it .. and it seems a more common name would be the ternary operator. Very good video on ternary operators @ vtc.com .. its one of their free php tutorial vids. Its seem though that these things are good only for echo .. lol .. perhaps its just happens to seem that way because all the example is jsut echo example.Can I do something like"(conditional statement) ? function_call(); some_other_functions(); another_function(); : print_error() ;"instead of just"(conditional statement) ? 'some text' : 'some other text'; " Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54253 Share on other sites More sharing options...
Cook Posted July 7, 2006 Share Posted July 7, 2006 No, for that you would have to use an if-else construct. Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54270 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 I would also suggest you to use if statement, it's much more easier to use.// OfftopicHey Cook, are your Surname [b]Guo[/b] ?Mine also :P Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54274 Share on other sites More sharing options...
kenrbnsn Posted July 7, 2006 Share Posted July 7, 2006 This is the Ternary Operator and is described in the PHP Manual at http://us3.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternarySometimes it's easier to use an if - then - else, sometimes the ternary operator, and sometimes a switch statement.Ken Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54380 Share on other sites More sharing options...
vr4lyfe Posted July 7, 2006 Author Share Posted July 7, 2006 Thanks guys. Consider me informed on ternary operators / concise conditionals now. ;) Quote Link to comment https://forums.phpfreaks.com/topic/13926-x-0-x-syntax-help/#findComment-54499 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.