Php – Ternary Operators

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-ternary-operators/
PINTEREST
PINTEREST
INSTAGRAM

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations

We have previously examined the if-elseif-else conditional statements. We know that these statements provides branching ability according to the conditions. While using this statements in single and simple situations it may become trivial task. Php provides an alternative way for a simple usage. This is called ternary operators.

Syntax

Syntax of ternary operator is like below. Php looks to the CONDITION and if the result is true the TRUE part is executed if not FALSE part code is executed.

Examples

Here we will check the login function status and if the login is successful the function will return true and true part of the ternary operator will be executed.

Advantages

  • Ternary operator will make code simpler
  • Ternary operator will make code more readable
  • Ternary operator will make code shorter
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-ternary-operators/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)