|
Posted by annmartinson on 08/23/06 09:58
yes, I've read and tried umpteen of the sort functions and still can't
get it right. which one do I need???
/////////////////////////////////////////////
here is my array:
$final[0]['name'] = "fire";
$final[0]['value'] = 0;
$final[0]['id'] = 1;
$final[0]['name'] = "air";
$final[0]['value'] = 0;
$final[0]['id'] = 2;
$final[0]['name'] = "infinity";
$final[0]['value'] = 0;
$final[0]['id'] = 3;
$final[0]['name'] = "water";
$final[0]['value'] = 0;
$final[0]['id'] = 4;
$final[0]['name'] = "earth";
$final[0]['value'] = 0;
$final[0]['id'] = 5;
Within my functional code, the 'value' keys are changed dynamically
based on returns from a form on a website. At this point, I want to
rearrange the array SORT_NUMERICAL, SORT_DESC so that the first two
records are the highest value. I then assign these two 'id' keys to
separate variables and use them to post the info requested back to the
site visitor.
I've tried
--- (1)
$final2 = arsort($final[value], SORT_NUMERIC);
$id = $final2[0]['id'];
$id2 = $final2[1]['id'];
---(2)
$final = array_multisort($final[value], SORT_NUMERIC, SORT_DESC);
$id = $final[0]['id'];
$id2 = $final[1]['id'];
---(3)
$final2 = array_multisort($final[value], SORT_NUMERIC, SORT_DESC,
$final[key]);
$id = $final2[0]['id'];
$id2 = $final2[1]['id'];
every one of these gave me various errors.
help is much appreciated. I'm sure the answer is MUCH simpler than I'm
managing :)
[Back to original message]
|