Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we will be studying about the PHP Ternary Operator.
Example
Try the following example to have a proper understanding of the ternary operator. Copy and paste the following program in text.php file and keep the file in your PHP Server's document root and then browse it by using any browser.
<html> <head> <title>Ternary Operator</title> </head> <body> <?php $a = 10; $b = 20; /* If condition is true then assign a to result otheriwse b */ $result = ($a > $b ) ? $a :$b; echo "TEST1 : Value of result is $result<br/>"; /* If condition is true then assign a to result otheriwse b */ $result = ($a < $b ) ? $a :$b; echo "TEST2 : Value of result is $result<br/>"; ?> </body> </html>
Output
When the above code is executed, it will produce the following result -
TEST1 : Value of result is 20 TEST2 : Value of result is 10
READ: PHP Assignment Operators
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about PHP Decision Making.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.