PDA

View Full Version : Tip: PHP Ternary operator


Chris
03-03-2004, 01:37 PM
This is a useful way to write your PHP if/else statements. It is called the Ternary operator.

(expr1) ? (expr2) : (expr3);

It says if expr1 is true then evaluate expr2 else evaluate expr3.

Here is the same thing using if/then:


if(expr1) {
expr2
} else {
expr3
}


It certainly makes for some cleaner code.

Eric
03-06-2004, 08:40 PM
Use the word ternary in a sentence not related to programming, I dare you.

dave
03-13-2005, 03:21 AM
Use the word ternary in a sentence not related to programming, I dare you.

The ternary nature of God can be very confusing.

Ternary periods seems to be unique to hockey.

-- Dave

Eric
03-13-2005, 09:03 AM
OK, you did it. But it took you a whole year to come up with 2 examples. :D

dave
03-13-2005, 11:23 AM
OK, you did it. But it took you a whole year to come up with 2 examples. :D

Yeah but it took me less than 5 minutes to come up with with them.

The real challenge will be to use 'ternary' in a poem.... That may take a while. :confused:

-- Dave

dave
03-14-2005, 03:42 AM
I'm way to weary to rhyme 'Ternary'
And if I could It'd be way to scary.

rckwldrn
10-06-2007, 11:36 AM
Use the word ternary in a sentence not related to programming, I dare you.


Ternary A musical form consisting of three main sections.

"Today i wrote a ternary song, it had only a verse, a chorus and a bridge"