Is tertiary operator possible here?
Posted
by
silow
on Stack Overflow
See other posts from Stack Overflow
or by silow
Published on 2010-12-31T02:29:58Z
Indexed on
2010/12/31
2:54 UTC
Read the original article
Hit count: 166
php
I'm trying to set $value1, $value2, $value3 entirely using tertiary operators. This is what it looks like without tertiary
if ($chk1 == 20) {
$value1 = true;
if ($chk2 == 40) {
$value2 = 100 ;
$value3 = 300;
} else {
$value2 = 200 ;
$value3 = 400;
}
} else {
$value1 = false;
}
I can set $value2 and $value3, but not sure how to set $value1. Can it be done?
if ($chk1 == 20) {
$value1 = true;
$value2 = ($chk2 == 40) ? 100 : 200;
$value3 = ($chk2 == 40) ? 300 : 400;
} else {
$value1 = false;
}
© Stack Overflow or respective owner