所以我知道 MIN()可以让我从一个数组中的最低值,但我需要一个数组的3最低值。
假设我的数组被命名为 $ myArray的:
我用 ASORT($ myArray的)我的数组,然后的print_r($ myArray的)输出这样的:
阵列( [137] => 4.90416668118 [135] => 7.1203544474 [18] => 7.2476262434 [81] => 8.37903400152 [33] => 9.1074567001 [4] => 9.90788482793 [138] => 10.2493339987 [5] => 11.6024401676 [63] ......等等,直到 [124] => 8727.73285117 [153] => 8727.73285117 [117] => 8727.73285117)我
如何获得第3的值或X值第一我需要...
我应该已经指定:是否有可能与丢失钥匙要做到这一点
解决方案 ASORT($ yourarray,SORT_NUMERIC);的print_r(array_slice($ yourarray,0,3,真实));www.php/manual/en/function。 asort.php
www.php/manual/en/ function.array-slice.php
So I know that min() can get me the lowest value from an array, however I need the 3 lowest values from an array.
assuming my array is named $myArray:
I used asort($myArray) on my array, then print_r($myArray) outputs this:
Array ( [137] => 4.90416668118 [135] => 7.1203544474 [18] => 7.2476262434 [81] => 8.37903400152 [33] => 9.1074567001 [4] => 9.90788482793 [138] => 10.2493339987 [5] => 11.6024401676 [63]...and so on until [124] => 8727.73285117 [153] => 8727.73285117 [117] => 8727.73285117 )How can I get the 3 first values or the X first values should I need to...
I SHOULD HAVE SPECIFIED: Is it possible to do this with losing the keys?
解决方案 asort($yourarray, SORT_NUMERIC); print_r(array_slice($yourarray, 0, 3, true));www.php/manual/en/function.asort.php
www.php/manual/en/function.array-slice.php
更多推荐
从一个数组,PHP得到3个最低值
发布评论