PHP Ternary Operator Issue

User
not working
Assistant
The issue you're encountering is likely due to a misunderstanding of how the null coalescing operator (`??`) works. The null coalescing operator returns the value on the left if it exists and is not `null`; otherwise, it returns the value on the right. In your case, the expression:

$inquiries->priority==$pri ?? 'selected':''

is not structured correctly because the `??` operator cannot be mixed with the ternary operator in this way.

Here's a correct way to write this:

<?php echo ($inquiries->priority == $pri) ? 'selected' : ''; ?>

This uses the ternary operator properly to check if `$inquiries->priority` is equal to `$pri` and then outputs `'selected'` if true, or an empty string if false.

Let me know if this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *