PHP: Using ? and :

cburwell

Limp Gawd
Joined
Apr 2, 2005
Messages
269
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!
 
It's an alternative conditional structure. It works much the same as your standard if/else/elsif. It looks like this;

$result = condition() ? true : false;

A more complete explination is in the PHP manual, about half way down this page.
 
Thanks for the link and the explaination! I have to say the PHP documentation is probably some of the best documentation I have used.
 
Back
Top