Reply to Re: How to use ? and : in a program

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация