Ternary Operators


This operator takes three arguments – a condition, a result for true, and a result for false.
It is a shortcut of doing if statements. Here’s an example:


    $result = ($a < 16) ? 'true' : 'false';


    if ($a < 16) {
        $result = 'true';
    } else {
        $result = 'false';
    }

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s