Jump to content

Array hall of fame. (hard)


konnwat

Recommended Posts

i got an IRC bot that when you type !hof it brings up the hall of fame. one problem with the hall of fame is if two people have the same "ks" (killing skill) then it only shows one on the hof. heres my code.

[code]
<?PHP
if (stripos($line, ":!hof")>0) {
$hof = '';
$ksreverse = array_flip($ks);
$hofnum = 0;
    for ($i=100; $i>0; $i--) {
if (isset($ksreverse[$i])) {
    $hof[$hofnum] = $ksreverse[$i];
    $hofnum++;
    if ($hofnum == 3) {
break;
    }
}
    }
    fwrite($socket, "PRIVMSG $chan :Hall of Fame: 1st - ".ucwords($hof[0])." || 2nd - ".ucwords($hof[1])." || 3rd - ".ucwords($hof[2])."\r\n");
}
?>[/code]

I tried this one too find if the array has two keys with the same value but theres an error.

[code]
<?PHP
if (stripos($line, ":!hof")>0) {
$hof = '';
$ksreverse = array_flip($ks);
$hofnum = 0;
    for ($i=100; $i>0; $i--) {
if (isset($ksreverse[$i])) {
    $hof[$hofnum] = $ksreverse[$i];
    $hofnum++;
    if ($hofnum == 3) {
break;
    }
}
    }
    $samekscount = array_count_values($ks);
    $ksnicks = array_keys($ks);
    for ($i=0; $i<3; $i) {
        if($samekscount[$ks[$hof[$i]]] > 0) {
            for ($ii=0; $ii<count($ksnicks); $ii++) {
                if($ks[$ksnicks[$ii]] == $samekscount[$ks[$hof[$i]]])
                    if(isset($newhof[$i])) {
                        $newhof[$i+1] = $ksnicks[$ii];
                    } else {
                        $newhof[$i] = $ksnicks[$ii];
                    }
                }
            }
        }
    }
    if(isset($newhof[0])) {
        $hof[0] = $newhof[0];
    }
    if(isset($newhof[1])) {
        $hof[1] = $newhof[1];
    }
    if(isset($newhof[2])) {
        $hof[2] = $newhof[2];
    }
    fwrite($socket, "PRIVMSG $chan :Hall of Fame: 1st - ".ucwords($hof[0])." || 2nd - ".ucwords($hof[1])." || 3rd - ".ucwords($hof[2])."\r\n");
}
?>[/code]

please help, is there any way of asking php to search an array for ALL keys with a certain value?
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.