PHP 从 3 个变量中获取最大数 [英] PHP get largest number from 3 variables

查看:47
本文介绍了PHP 从 3 个变量中获取最大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
返回值最高的变量?

我试图想出一种简单的方法来找出 3 个变量中的最大数字.

I'm trying to come up with a simple way of finding the highest number out of 3 variables.

$1 = 100
$2 = 300
$3 = 200

在这 3 个变量中,我想将一个新变量设置为最高的变量 ($2)

out of those 3 variables, I want to set a new variable as the highest one ($2)

所以:

$highest_number = 300

推荐答案

$highest_number = max($1, $2, $3);

$values = array($1, $2, $3);
$highest_number = max($values);

其他信息可以在max的quickref

这篇关于PHP 从 3 个变量中获取最大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆