learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
Interesting one this and I have searched high and low for an answer...
I have an associative array where image types are given a score.
The array is set up in a loop so that the score is used as the key and the value is the name of the image type.
I am trying to return the image type (i.e. the value) from that array where it has the highest key (score).
I can't use a simple max() because it will only return a max value and not a max key.
Am I doing this the wrong way round? Should I set up ...
.. I can then easily obtain the highest score, but how do I get the associated key image type?
It's probably simple but I can't get my head round it.
Any help would be appreciated.
Richard
I have an associative array where image types are given a score.
The array is set up in a loop so that the score is used as the key and the value is the name of the image type.
PHP:
$imageScores [$score] = $imageType;
I am trying to return the image type (i.e. the value) from that array where it has the highest key (score).
I can't use a simple max() because it will only return a max value and not a max key.
Am I doing this the wrong way round? Should I set up ...
PHP:
$imageScores[$imageType] = $score;
.. I can then easily obtain the highest score, but how do I get the associated key image type?
It's probably simple but I can't get my head round it.
Any help would be appreciated.
Richard
Last edited: