16

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
  • 313
  • 1
  • 3
  • 12
  • 3
    *I tried in many way* I don't see a single one, please show us your attempts – Rizier123 Feb 19 '15 at 09:13
  • It has been set duplicated but the best link, given the question, would have been this https://stackoverflow.com/questions/16405986/inline-php-html-ternary-if – Robert Apr 16 '23 at 16:10

2 Answers2

37

Use this code

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

It should be like this:

<?php echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : "#ffffff"; ?>
Albzi
  • 15,431
  • 6
  • 46
  • 63