14

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";

}

?>
sayful
  • 193
  • 1
  • 1
  • 11

2 Answers2

34

Use this code

echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : '#ffffff';
Sunil Pachlangia
  • 1,963
  • 2
  • 13
  • 25
4

It should be like this:

<?php echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : "#ffffff"; ?>
Albzi
  • 15,201
  • 5
  • 43
  • 61