1

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 Style Option

Style Edit

<dt> Style </dt>
<dd> <?php $styles=styles(); 
if(isset($styles[$user->style]))echo $styles[$user->style];
?> </dd>

1 Answer 1

1

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';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.