Can someone tell me what this piece of code is doing?

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
asecaida
Forum Newbie
Posts: 2
Joined: Tue Jul 29, 2008 4:47 pm

Can someone tell me what this piece of code is doing?

Post by asecaida »

Say $count = 2 and $max_points = 3 and also vice versa.

$order_points = ($count >= $max_points) ? $max_points : $count;


Thanks.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Can someone tell me what this piece of code is doing?

Post 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.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Can someone tell me what this piece of code is doing?

Post 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.
asecaida
Forum Newbie
Posts: 2
Joined: Tue Jul 29, 2008 4:47 pm

Re: Can someone tell me what this piece of code is doing?

Post by asecaida »

Thanks for the help fellas.
Post Reply