Originally posted by mattwade
foreach ($records as $record) {
$sortarray[] = $record['hit_number'];
}
array_multisort($records, $sortarray);
should do it...
Dear mattwade,
I'm trying what you recommended and having a little trouble. Note that I'm actually keeping each $record in an array called $list (via a $list[]=$record line at the end of a loop).
Now, here's what I'm trying. Note the slight variation... I'm using a "while" statement, just because it's what I was already trying to do, plus I can verify what's happening with my already-written echo command.
reset ($list);
while (list($key, $value)= each ($list)){
echo "key=$key value=$value<BR>";
$sortarray[] = $value['hit_number'];
}
array_multisort($list, $sortarray);
echo "<BR></BR>SORTED !!<BR></BR>";
reset($list);
while (list($key, $value)= each($list)){
$this_cat_num= $list[$key]['cat_number'];
$this_good_row_number = $list[$key]['row'];
$this_title_link = $list[$key]['title_link'];
$this_hit_number= $list[$key]['hit_number'];
echo "cat_num=$this_cat_num cat_name=$this_cat_name title_link=$this_title_link hit_number= $this_hit_number<BR>";
}
The second loop through the array shows the exact same sort order as before.
So, $sort_array is going to be an array of numbers in any old order, with some probably repeating, right?
(example: 0,1,13,24,1,0,0,3,0 )
I've never used the array_multisort command. That's going to sort my entire array of records according to this set of numbers?
Thanks!
-= Dave =-