开发者

Compare integers [closed]

开发者 https://www.devze.com 2023-02-06 08:47 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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