Solved

easy array question, get highest value or value

Posted on 2008-10-30
3
487 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now