Reputation: 25745
i would like to use Ternary Operator for the below code..
<?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?
Upvotes: 3
Views: 748
Reputation: 816334
Just for fun a different way:
$msg = array(true => 'Yes', false => 'No');
echo $msg[(users['active'] == 1)];
Upvotes: 1
Reputation: 157839
<? if ($users['active']): ?>Yes<? else: ?>No<? endif ?>
Upvotes: 0
Reputation: 20602
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"); ?>
Upvotes: 12