Page 1 of 1

Anyone know what this is?

Posted: Fri Oct 15, 2010 6:51 pm
by MythX
I think this is an older way of doing something in PHP. Can anyone point me to a decent document on it, or even describe what this line is doing?

Thanks

Jason

$Delimiter = empty($xml->DELIMITER->attributes()->value) ? "\t" : chr($xml->DELIMITER->attributes()->value);

Re: Anyone know what this is?

Posted: Fri Oct 15, 2010 7:30 pm
by mkz
The line makes use of the Ternary operator.

The expression "A ? B : C" means: if A is true, evaluate to B, otherwise evaluate to C.

In this case, A is checking whether the value is empty with the empty() function. If it is, the expression evaluates to "\t". If not, it evaluates to the value itself.

It's a common use of the ternary operator: using a default value if a value is not set.

Re: Anyone know what this is?

Posted: Fri Oct 15, 2010 8:29 pm
by MythX
That makes sense. Thanks for clearing it up.