How to find the maximum value among three numbers in PHP?

You can use three variables to compare the sizes of three numbers and then find the largest value.

Here is an example code:

function findMax($num1, $num2, $num3) {
   $max = $num1;

   if ($num2 > $max) {
      $max = $num2;
   }

   if ($num3 > $max) {
      $max = $num3;
   }

   return $max;
}

$num1 = 3;
$num2 = 7;
$num3 = 2;

$max = findMax($num1, $num2, $num3);
echo "最大值是:".$max;

The output is: the maximum value is 7.

bannerAds