Forum Moderators: coopster

Message Too Old, No Replies

Quick syntax explanation

         

Scally_Ally

11:51 am on Mar 19, 2007 (gmt 0)

10+ Year Member



Hi All,
This is just a quick question - I work on alot of systems that other people have created and i see this sort of syntax alot,

$scaleH = ($maxH > 0)? $maxH / $h : 1;

I know that this is prob a real newb question but i have never been taught this kind of syntax before..

Is it translated to something like

if($maxH > 0){
$scaleH = $maxH / $h;
}else{
$scaleH = 1;
}

Thanks in advance.

Ally

jatar_k

12:42 pm on Mar 19, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it's called the ternary operator
[php.net...]

The expression (expr1)? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.

Scally_Ally

1:35 pm on Mar 19, 2007 (gmt 0)

10+ Year Member



Thanks alot jatar