Re: array problem need help quick
| From: | Ignatius Reilly | Date: | Sun, 01 Dec 2002 09:43:54 +0000 |
| Subject: | Re: array problem need help quick | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-17230@lists.php.net to get a copy of this message | ||
When looping your SELECT result (or whatever), feed two arrays:
$arr[] = array(
"name" => "marmite",
"tally" => 10 ) ;
+ an "index" array that will serve to rank items:
$rank[] = 10 ;
Now you sort $rank on the value.
The whole idea is that you will not need to sort $arr (you can, but it is
needlessly complicated: usort()...)
To call the elements of $arr in the right order, loop $rank:
foreach ( $rank as $r ) {
// the element you need is $arr[$rank[$r]]['name'], etc.
HTH
Ignatius
____________________________________________
----- Original Message -----
From: "DaMouse" <damouse@ntlworld.com>
To: "PHP - Win" <php-windows@lists.php.net>
Sent: Sunday, December 01, 2002 6:17 AM
Subject: [PHP-WIN] array problem need help quick
I need help with a array problem I want one array to be sorted and another
taking its same number order e.g.
$ar1[0] == "marmite"; $ar2[0] == 10;
$ar1[1] == "jam"; $ar2[1] == 11;
$ar1[2] == "beef"; $ar2[2] == 7;
$ar1[3] == "cabbage"; $ar2[3] == 0;
$ar1[4] == "ick"; $ar2[4] == 5;
sort($ar2,SORT_NUMERIC); and then make sure that the values of $ar1 are with
there vote number counterparts in $ar2 so now
$ar2[0] == 0; $ar1[0] == "cabbage";
please help
Ensign Baker
HCO Officer
USS Atlantis