dongyixiu3110 2014-05-01 19:15
浏览 69
已采纳

PHP使用asort排序后只显示数组的第一个结果?

I have an array containing only numbers, i want to sort them using asort so it shows the lowest number first.

but now i have the array sorted, how do i make it show only the first result?

For instance, this is my array:

Array ( [0] => 399 [1] => 349  ) 

and after asort:

Array ( [1] => 349 [0] => 399 ) 

how do i echo only the first result after i asort as i cant just use Array[1] because it might not always be [1] etc..

Sorry if this is a dumb question, but its late and my brain has ceased to function correctly lol.

  • 写回答

2条回答 默认 最新

  • dreamlife2014 2014-05-01 19:16
    关注

    Just use sort() which won't maintain key association.

    $array = array(399, 349);
    sort($array);
    print_r($array);
    // Array ( [0] => 349 [1] => 399 )
    

    Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度