开发者

Compare integers [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can b开发者_如何学Ce reopened, visit the help center. Closed 12 years ago.
$a = somenumber;
$b = somenumber;

How do I know which variable has the biggest number? What is the shorter way for this task.

Each number is a positive integer without residue.

Thanks.


max returns the largest value from a list of values:

$biggest = max($a, $b);

If you care about which variable contains a higher value, use >, as other answers have said.


You can use ternary operator:

$big = ($a > $b) ? $a : $b;


Kidding?

if ($a > $b) {
    // $a is bigger
} else {
    // $b is bigger
}

or

$bigger = max($a, $b);


function is_a_bigger($a, $b) {
    return ($a - $b > 0);
}


if ($a > $b) {
 echo '$a is bigger';
} else 
 echo '$b is bigger';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜