Php – Ternary Operators

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

[rps-include post=6522]

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
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)