|
Posted by Michael Jack on 10/11/05 12:32
Many thanks for the prompt reply.
Regards,
"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spamyourself.com> wrote in
message news:434b806c$0$11061$e4fe514c@news.xs4all.nl...
> Michael Jack wrote:
>
>> 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.
>
> Hi Michael,
>
> It is just a shorthand notation for an if-then-else statement
>
> eg:
> $a = 10;
> echo ( ($a<20) ? "$a is smaller then 20!" : "$a is not smaller then 20!");
>
> is the same as:
> $a = 10;
> if ($a<20) {
> echo "$a is smaller then 20!";
> } else {
> echo "$a is not smaller then 20!";
> }
>
> Regards,
> Erwin Moller
>
>
>>
>> <?
>> $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";
>> ?>
>>
>> This recursive program is used to find the greatest common denominator of
>> 2 numbers.
>>
>> TIA
>
Navigation:
[Reply to this message]
|