__destruct Posted July 20, 2009 Share Posted July 20, 2009 I was wondering would the following return 0 if the condition is met, and 1 if it is not? $a = 0; $b = 1; return ($password == $data['password']) ? $a : $b; Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/ Share on other sites More sharing options...
trq Posted July 20, 2009 Share Posted July 20, 2009 Yes, that is correct. Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878562 Share on other sites More sharing options...
__destruct Posted July 20, 2009 Author Share Posted July 20, 2009 So it would be as if I had typed: if (cond) { return 0; } else { return 1; } Is that correct, or no? Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878564 Share on other sites More sharing options...
thebadbad Posted July 20, 2009 Share Posted July 20, 2009 Correct. Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878565 Share on other sites More sharing options...
__destruct Posted July 20, 2009 Author Share Posted July 20, 2009 Thank you both very much! I have spent about an hour trying to get the ternary operator to work with return. Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878566 Share on other sites More sharing options...
thebadbad Posted July 20, 2009 Share Posted July 20, 2009 No offence, but wouldn't it be faster to just test your code instead of asking how it would work? Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878574 Share on other sites More sharing options...
__destruct Posted July 20, 2009 Author Share Posted July 20, 2009 I did test it. I was just wondering if the outcome would be the same as the example I had given since I am still in the middle of my project, and testing hasn't been made available yet. Link to comment https://forums.phpfreaks.com/topic/166614-ternary-operator-returns/#findComment-878580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.