Welcome to WebmasterWorld Guest from 23.20.75.214

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP and ?

     
7:50 pm on Aug 16, 2001 (gmt 0)

Preferred Member

10+ Year Member

joined:May 3, 2001
posts:365
votes: 0


Quick question.

What does the ? (question mark) do in PHP?

Or more to the point.

I'm trying to convert this javascript

X = (!X ? 2 : X);

to PHP

It's supposed to mean I think

if X is not true then use X, else if it is true then use 2

I think

Thanks

9:34 pm on Aug 16, 2001 (gmt 0)

Preferred Member

10+ Year Member

joined:May 9, 2001
posts:416
votes: 0


Ternary operator.

$first ? $second : $third
If the value of the first subexpression is TRUE (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.

[php.net...] (find: ternary)

2:30 pm on Aug 17, 2001 (gmt 0)

Preferred Member

10+ Year Member

joined:May 3, 2001
posts:365
votes: 0


You know I could not find this information in any of my PHP books. And I got three of them.

Thanks for the answer