ternary operator in php with echo value

sayful picture sayful · Feb 19, 2015 · Viewed 22.6k times · Source

I want to write the following code in ternary operator. I tried in many way but it does not work at all.

<?php 

if(isset($options['footer_txt_color'])) {

    echo $options['footer_txt_color'];

} else {

    echo "#ffffff";

}

?>

Answer

Sunil Pachlangia picture Sunil Pachlangia · Feb 19, 2015

Use this code

echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : '#ffffff';