Get the name of the variable which has the highest/biggest value with PHP

php

Solution

Here is a solution to the question you asked:

$arr = compact('v1', 'v2', 'v3', 'v4');
arsort($arr);
$name = key($arr);
// get the value: ${$name}

However, having the variables stored in an array in the first place would make more sense. A better setup would be:

$arr = array('v1' => 543, 'v2' => 41, 'v3' => 1, 'v4' => 931);
arsort($arr);
$name = key($arr);
// get the value: $arr[$name]

Problem

I have 4 variables and each of those have an integer assigned to them. Could anybody please let me know how I can get the name of the variable which has the highest value? Thanks in advance.

Original source