Posted by Jerry Sievers on 10/11/05 14:21
"Michael Jack" <michael@jack2005.com> writes:
> Hi,
>
> in the program below, what is the meaning/use of
> the question mark (?gcd) and the colon (:$a) after the return statement? Any
> explanation will be appreciated.
>
> <?
> $x=32;
> $y=80;
> function gcd($a, $b)
> { return ($b>0)?gcd($b,$a%$b):$a;}
> $val=gcd($x, $y);
> print "The greatest common denominator of $x and $y is $val";
You have stumbled on the ternary operator;
But the real reason for this is to obfuscate the program and confuse
everyone who reads it!
No kidding. I quit using ?: years ago and prefer the more verbose
if/then/else. Others may disagree.
HTH
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
[Back to original message]
|