PHP Ternary Conditional Operator
Ternary Operator is a conditional assignment in which you can assign the condition as well as either two different values that can be assigned to the target variable based on the condition.
Ternary Operator performs conditional operators. Ternary operators simplify some PHP conditional statement. But not simplify all the PHP conditional statements.
Ternary Operator is denoted by “?” symbol.
Example 1 – PHP Ternary Conditional Operator Example with Code Syntax
<!DOCTYPE html> <html> <head> </head> <body> <?php $x = 7; $x = ($x<=18) ? 'Not Eligible for Vote' : 'Eligible for Vote'; echo $x; ?> </body> </html>
In the above code, we uses ternary operator “?” to perform the task to know the value of variable $x is eligible for vote or not.
In this code, we define the value of $x is 7 and condition is if the value of $x less than 18 than print not eligible for the vote, if not then print not eligible.
Thanks for ones marvelous posting! I seriously enjoyed reading it, you may be a great author.I will ensure that I bookmark your blog and will come back from now on. I want to encourage that you continue your great work, have a nice weekend!