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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.