Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ternary operator in php with echo value [duplicate]

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

}

?>
like image 740
sayful Avatar asked Feb 19 '15 09:02

sayful


2 Answers

Use this code

echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : '#ffffff';
like image 118
Sunil Pachlangia Avatar answered Sep 29 '22 20:09

Sunil Pachlangia


It should be like this:

<?php echo (isset($options['footer_txt_color'])) ? $options['footer_txt_color'] : "#ffffff"; ?>
like image 29
Albzi Avatar answered Sep 29 '22 19:09

Albzi