Jump to content

Array sort


drisate

Recommended Posts

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
        )

)

Link to comment
https://forums.phpfreaks.com/topic/199197-array-sort/
Share on other sites

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>');

    }
}

Link to comment
https://forums.phpfreaks.com/topic/199197-array-sort/#findComment-1045512
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.