What is the ternary operator in PHP and how is it used in conditional statements?

The ternary operator in PHP is a shorthand way of writing conditional statements that evaluate an expression and return different values based on whether the condition is true or false. It is written as a question mark followed by a colon, like so: (condition) ? value_if_true : value_if_false. This operator can be used to simplify if-else statements and make code more concise. Example:

// Using ternary operator to check if a number is even or odd
$num = 10;
$result = ($num % 2 == 0) ? "even" : "odd";
echo $result; // Output: even