How to use ternary operator in php?

Server & Coding ForumCategory: QuestionsHow to use ternary operator in php?
s k asked 4 months ago PPU : 10
Question Tags:




2 Answers

Best Answer

kundu sujan answered 4 months ago

(Condition) ? (Text1) : (Text2);
Condition: It returns a boolean value (true and false).
Text 1: If the condition returns true state then this Text to be executed.
Text 2: If the condition returns fales state then this Text to be executed.

developer2016 answered 4 months ago

The ternary operator works like this:

(Condition) ? (true) : (false);

Example:

$number = 35;

$number >= 30 ? "pass" : "Fail";