Raffy T Lawrence Raffy T Lawrence - 2 months ago 8
PHP Question

PHP : How to get the lowest array value together of the key

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

Answer
$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;