Page 1 of 1
Can someone tell me what this piece of code is doing?
Posted: Tue Jul 29, 2008 4:49 pm
by asecaida
Say $count = 2 and $max_points = 3 and also vice versa.
$order_points = ($count >= $max_points) ? $max_points : $count;
Thanks.
Re: Can someone tell me what this piece of code is doing?
Posted: Tue Jul 29, 2008 6:03 pm
by jayshields
if $count is more than or equal to $max_points then $order_points is changed to $max_points' value, else it is changed to the value of $count.
Google for the ternary operator.
Re: Can someone tell me what this piece of code is doing?
Posted: Wed Jul 30, 2008 2:59 am
by Phoenixheart
Yeah, and it's equivalent to
Code: Select all
if ($count >= $max_points)
{
$order_points = $max_points;
}
else
{
$order_points = $count;
}
This can be applied to function executing too, for an example:
Code: Select all
$count >= $max_points ? do_this() : do_that();
Cheers.
Re: Can someone tell me what this piece of code is doing?
Posted: Wed Jul 30, 2008 6:35 pm
by asecaida
Thanks for the help fellas.