![]() |
|
|
+ Search |
![]()
|
Nov 28th, 2001 19:37
Philip Olson, Mats Remman, feiy hy, Craig Fratrik,
Yes, the ternary operator is also available in PHP. Here's an example
use:
$bgcolor = ($i++ % 2) ? '#ffffff' : '#000000';
Which behaves exactly like the following:
if ($i++ % 2) {
$bgcolor = '#ffffff';
} else {
$bgcolor = '#000000';
}
A mention in the PHP Manual exists here:
http://www.php.net/manual/en/language.expressions.php
http://www.php.net/manual/en/language.operators.comparison.php
And for informational purposes (unrelated to this question), the % in
the above example is called "Modulus" which is further explained here:
http://www.faqts.com/knowledge_base/view.phtml/aid/783/fid/9