One line if / else clause in PHP


Create an “if / else” check in one line.


For assigning a value, or triggering a special function based on an “if / else” clause we can use the one line clause from PHP:

$our_variable = (is_this_true()) ? “value in case of true” : “value in case of false”;


Where is_this_true() is the function or variable that has to be checked for validity.


About admin

Just another php developer trying to give something back to the community.
This entry was posted in PhP and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s