Explain the ternary conditional operator in PHP?

Recommended Answers

All 2 Replies

condition ? true :false

variable = (condition) ? value-if-true : value-if-false;
ex:
$greeting = (date("G") < 12) ? 'Good morning' : 'Good afternoon'; echo $greeting;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.