doufeikuang7724 2016-09-13 19: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-13 20: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条)
编辑
预览

报告相同问题?