简体   繁体   English

PHP获取最低阵列值的阵列键

[英]PHP get array key for lowest array value

Using PHP, I am creating an array that contains multiple keys: 使用PHP,我正在创建一个包含多个键的数组:

$loadAverage[$server] = $output["now"];

I am then checking the item with the lowest value 然后,我正在检查价格最低的商品

echo min($loadAverage);

but i need to get the key of the array not the value (so the $server part i need) 但是我需要获取数组的键而不是值(所以我需要$server部分)

the above is returning the value and not the key of the PHP array 上面的返回值,而不是PHP数组的键

echo min(array_keys($loadAverage));
$lowest_key = array_keys($loadAverage, min($loadAverage));
echo $lowest_key[0];

By supplying a search element you only get the key of that value. 通过提供搜索元素,您只会获得该值的关键字。

echo array_search(min($loadAverage), $loadAverage);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM