Anyone know what this is?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MythX
Forum Commoner
Posts: 28
Joined: Mon Jan 11, 2010 8:28 pm

Anyone know what this is?

Post 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);
mkz
Forum Newbie
Posts: 11
Joined: Tue Oct 05, 2010 10:37 am

Re: Anyone know what this is?

Post 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.
MythX
Forum Commoner
Posts: 28
Joined: Mon Jan 11, 2010 8:28 pm

Re: Anyone know what this is?

Post by MythX »

That makes sense. Thanks for clearing it up.
Post Reply