0

Using PHP, I am creating an array that contains multiple keys:

$loadAverage[$server] = $output["now"];

I am then checking the item with the lowest value

echo min($loadAverage);

but i need to get the key of the array not the value (so the $server part i need)

the above is returning the value and not the key of the PHP array

1
  • 1
    use an array_search() for that minimum value, which will return the key Commented Mar 9, 2015 at 23:11

3 Answers 3

1
echo min(array_keys($loadAverage));
Sign up to request clarification or add additional context in comments.

8 Comments

this is returning a number - it returns 0 which is the first array item
Now the question is if OP wants the lowest key or the lowest value and the key from the value
i want the lowest value and i need the key to be returned
@Rizier123 you are directing him to his own question?
|
1
$lowest_key = array_keys($loadAverage, min($loadAverage));
echo $lowest_key[0];

By supplying a search element you only get the key of that value.

2 Comments

this is returning Array
the value is in the array
0
echo array_search(min($loadAverage), $loadAverage);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.