- PHP

Get the Key of the Largest Value in the PHP array

Use array_search() and max() functions.

array_search(max($array), $array);

Example:

Get the oldest person name from the array.

<?php

$people = [
    "Adam" => 32,
    "John" => 50,
    "Richard" => 34,
    "Steve" => 26, 
];

echo 'Oldest person: ' . array_search(max($people), $people);

?>

Output: Oldest person: John