Reputation: 49
I have one field Style, in this field I have few options to select, but what I want is when the person doesn't select any style, in the field I want to display the text "N/A" How I can do that?
Now display nothing if i dont select the style
<dt> Style </dt>
<dd> <?php $styles=styles();
if(isset($styles[$user->style]))echo $styles[$user->style];
?> </dd>
Upvotes: 1
Views: 43
Reputation: 147156
If you're using PHP7, you can use the null coalescing operator to give a default value when a variable isn't set:
echo $styles[$user->style] ?? 'N/A'
In earlier versions, use the ternary operator:
echo isset($styles[$user->style]) ? $styles[$user->style] : 'N/A';
Upvotes: 1