cburwell Posted September 24, 2006 Share Posted September 24, 2006 I posted this somewhere else, but I figured this might be a better place.I have been looking around for what the use of ?, and : mean in PHP, such as in the following examples$data = (file_exists($data)) ? $this->parse($data) : $data;and$func = ( $regType == 'P' ) ? 'preg_match' : 'ereg' . $case;Could someone point me in the right direction of some documentation on this? I have tryed searching, but I can't seem to search for the uses of ? and : properly.Thank you! Quote Link to comment Share on other sites More sharing options...
trq Posted September 24, 2006 Share Posted September 24, 2006 A little way down the page [url=http://www.php.net/manual/en/language.operators.comparison.php]here[/url]. The ternary operator. Quote Link to comment Share on other sites More sharing options...
cburwell Posted September 25, 2006 Author Share Posted September 25, 2006 Thank you! I appreciate your help. Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 25, 2006 Share Posted September 25, 2006 To make a long story short:(mixed return type) = condition ? (what to do if it's true) : (what to do if it's false);The statement returns whatever it evaluates to; for example, [code]$condition = true;$value = $condition ? "three" : 19;[/code]$value will now contain (string) (5) "three". [code]$condition = false;$value = $condition ? "three" : 19;[/code]$value now contains (int) 19. Quote Link to comment 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.