doufeikuang7724 2016-09-14 03:56
浏览 28
已采纳

PHP:如何获得密钥的最低数组值

I have a an array and I need to get the lowest value together of key. Because i need to check if the value has contain the right key or not

 Array ( 
      [120] => 97.00 
      [132] => 92.67 
      [124] => 72.33 
      [131] => 49.67 
      [129] => 25.00 
      [127] => 25.00 //<--Get the value and this key
  )
  //This array already sorted, no need to sort just get the last value and key

How can i get the lowest value 25.00 together the key [127]

 $array = array (

      "120" => 97.00 
      "132" => 92.67 
      "124" => 72.33 
      "131" => 49.67 
      "129" => 25.00 
      "127" => 25.00 

  );

  print_r(min($array)); //<--displaying only the value but not the key

The output should be like

127 - 25.00
  • 写回答

4条回答 默认 最新

  • douzhi4830 2016-09-14 04:15
    关注
    $array = array (
          "120" => 97.00, 
          "132" => 92.67,
          "124" => 72.33,
          "131" => 49.67,
          "129" => 25.00,
          "127" => 25.00 
    
      );
        // point the last element of the element and fetch value to $value
        $value= (end($array));
        // fetch key
        echo "key : ". key($array);
        echo "value :".$value;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?