i would like to use Ternary Operator for the below code..
&l开发者_运维问答t;?php
if($users['active'] == 1 )
{
echo 'Yes';
}
else
{
echo 'No';
}
?>
i tried using this code and it does not work..
<?php ($users['active'] == 1) ? echo "Yes" : echo "No"; ?>
what is wrong?
The echo
goes outside of it, not in, it (the ternary operator) is returning a value, not a codeblock.
<?php echo ($users['active'] == 1 ? "Yes" : "No"); ?>
Just for fun a different way:
$msg = array(true => 'Yes', false => 'No');
echo $msg[(users['active'] == 1)];
<? if ($users['active']): ?>Yes<? else: ?>No<? endif ?>
精彩评论