Possible Duplicate:
the code “ : ” in php
I often see a lot of php code using ? and :, but I don’t actually understand what it is for. Here an example:
$selected = ($key == $config['default_currency']) ? ' selected="selected"' : '';
Can someone clear me up, please? 🙂
evaluates to
val1ifconditionis true, orval2ifconditionis false.Since PHP 5.3, you may also see an even more obscure form that leaves out
val1:evaluates to
val0ifval0evaluates to a non-false value, orval2otherwise. Yikes!See http://php.net/manual/en/language.operators.comparison.php