Solved

easy array question, get highest value or value

Posted on 2008-10-30
3
490 Views
Last Modified: 2008-10-30
I have an array.

$score[7] = 19;
$score[4] = 7;
$score[6]=23;

I want to get the key of the one that has the highest value...
0
Comment
Question by:phenixfilms
  • 2
3 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 22844591
$maxval = "0";
foreach ($score as $key => $val) {
 if ($val > $maxval) {
  $maxkey = $key;
}
}
echo $maxkey;
0
 
LVL 17

Expert Comment

by:psimation
ID: 22844603
OOPS, forgot maxval...

$maxval = "0";
foreach ($score as $key => $val) {
 if ($val > $maxval) {
  $maxval = $val;
  $maxkey = $key;
}
}
echo $maxkey;
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 125 total points
ID: 22844613
$score = array();

$score[7] = 19;
$score[4] = 7;
$score[6]=23;

arsort( $score );
$keys = array_keys( $score );

echo $keys[0];
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question