Page 1 of 1
triyng to understand this code
Posted: Tue Oct 10, 2006 5:43 pm
by iffo
Hi,
I have never seen this syntax what is going on here?
echo ($this->pixel=="iframe")?$this->affil_pixel():"";
Thanks
Posted: Tue Oct 10, 2006 5:46 pm
by volka
Posted: Tue Oct 10, 2006 5:47 pm
by feyd
It's called a ternary or trinary operator.
Basically, it's a compact version of and if..else construct.
expression1 ? expression2 : expression3 is analogous to if( expression1 ) expression2; else expression3;
Posted: Tue Oct 10, 2006 6:03 pm
by Luke
something that should have been obvious, but I just realized recently is that it's called the ternary operator because it's the only operator that works on three expressions at once...

Posted: Tue Oct 10, 2006 6:45 pm
by iffo
thanks I understand now, but why echo? what role echo is playing here ?
Posted: Tue Oct 10, 2006 6:51 pm
by RobertGonzalez
echo() prints to the screen (similar to
print()).
Posted: Tue Oct 10, 2006 6:56 pm
by Luke
So, to extend that to feyd's example...
echo expression1 ? expression2 : expression3 is analogous to if( expression1 ) echo expression2; else echo expression3;
Posted: Wed Oct 11, 2006 7:40 am
by iffo
perfect ....... thanks a lot