Home  >  Article  >  Backend Development  >  取出数组中,前三小的三个单元,非连续索引数组

取出数组中,前三小的三个单元,非连续索引数组

WBOY
WBOYOriginal
2016-06-23 13:15:58753browse

$arr =array(	11=>2530,	13=>8922,	26=>250,	77=>250,	88=>1230,	99=>12);

以上数组,怎么样才能取出最小的三项:
array(99=>12,26=>250,77=>250)


回复讨论(解决方案)

$arr =array(    11=>2530,    13=>8922,    26=>250,    77=>250,    88=>1230,    99=>12);asort($arr);print_r(array_slice($arr, 0, 3, true));
Array(    [99] => 12    [77] => 250    [26] => 250)

$arr =array(    11=>2530,    13=>8922,    26=>250,    77=>250,    88=>1230,    99=>12);asort($arr);print_r(array_slice($arr, 0, 3, true));
Array(    [99] => 12    [77] => 250    [26] => 250)


我真是糊涂了,竟然忘了asort和array_slice,谢谢版主大人,又一次帮了我~~~
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php长连接Next article:php curl 发送post请求