Can you provide examples of best practices for using the ternary operator in PHP code?

Using the ternary operator in PHP can help simplify conditional statements and make code more concise. One best practice is to use parentheses to improve readability, especially when nesting ternary operators. Another best practice is to use the ternary operator for simple conditional assignments, rather than complex logic.

// Example of using ternary operator with parentheses for improved readability
$age = 25;
$isAdult = ($age >= 18) ? "Yes" : "No";

// Example of using ternary operator for simple conditional assignments
$score = 85;
$result = ($score >= 70) ? "Pass" : "Fail";