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! Link to comment https://forums.phpfreaks.com/topic/21902-using-and/ 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. Link to comment https://forums.phpfreaks.com/topic/21902-using-and/#findComment-97821 Share on other sites More sharing options...
cburwell Posted September 25, 2006 Author Share Posted September 25, 2006 Thank you! I appreciate your help. Link to comment https://forums.phpfreaks.com/topic/21902-using-and/#findComment-97844 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. Link to comment https://forums.phpfreaks.com/topic/21902-using-and/#findComment-97845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.