drisate Posted April 20, 2010 Share Posted April 20, 2010 I have an array that looks like this Array ( [22] => Array ( [113] => 6 [154] => 1 [166] => 4 ) ) How can i sort the 6, 1, 4 to look like this? Array ( [22] => Array ( [113] => 6 [166] => 4 [154] => 1 ) ) Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 20, 2010 Share Posted April 20, 2010 arsort($array[22]); $array=array_reverse($array[22]); Quote Link to comment Share on other sites More sharing options...
drisate Posted April 21, 2010 Author Share Posted April 21, 2010 I tryed it and i get Warning: Invalid argument supplied for foreach() in /var/www/vhosts/dramis.info/httpdocs/index.php on line 160 I think you code is breaking the array $select = mysql_query("SELECT usergroupid, userid FROM vb_user AS u CROSS JOIN vb_post AS p USING(userid) WHERE dateline > UNIX_TIMESTAMP(CURDATE() - INTERVAL 30 DAY) AND u.usergroupid = 22") or die(mysql_error()); while ($list = mysql_fetch_array($select)) { $store[$list['usergroupid']][$list['userid']] += 1; } arsort($store[22]); $store=array_reverse($store[22]); foreach($store as $k => $v) { foreach($v as $kk => $vv) { unset($wuser); $wuser = @mysql_fetch_array(@mysql_query("SELECT * FROM vb_user WHERE userid='$kk'")); print ('<tr vAlign="top"><td class="thead" align="left" width="20%"><a href="board/member.php?u='.$wuser[userid].'"><font color="#FFFFFF">'.$wuser[username].'</font></a></td><td class="thead" align="left" width="80%"><font color="#FFFFFF">'.$vv.'</font></td></tr>'); } } Quote Link to comment Share on other sites More sharing options...
salathe Posted April 21, 2010 Share Posted April 21, 2010 It looks like you want $store[22] = array_reverse($store[22]); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.