PHP - 使这段代码更短

I have this PHP code (get_option is Wordpress function).

    <?php $hahaha = get_option('hahaha'); 
    if(empty($hahaha)) { 
       echo 'false'; 
    } 
    else { 
       echo 'true'; 
    }
?>

The code looks lame to me, is there a way of making it shorter like (my imagination ;)):

<?php $hahaha = get_option('hahaha');
if($hahaha): 'true' // 'false'
?>
$hahaha = get_option('hahaha'); 
echo $hahaha ? 'true' : 'false';

There's no need for empty, since the variable is definitely set. A pure boolean comparison works just fine.

If you don't need the variable later on for something else, you can skip it as well:

echo get_option('hahaha') ? 'true' : 'false';
$hahaha = get_option('hahaha');
echo empty($hahaha) ? 'true' : 'false';

See http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary for more details about the ternary operator.

You can use a ternary operator, but I'm not sure it does much for readability:

echo (empty($hahaha) ? 'false' : 'true');
echo empty($hahaha)?'false':'true';
echo empty($hahaha = get_option('hahaha')) ? 'false' : 'true';
<?php $hahaha = get_option('hahaha');
echo (isset($hahaha)) ? 'true': 'false';

This will display 0 or 1

$options = get_options(...);

echo empty($options); OR echo !empty($options);