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
https://forums.phpfreaks.com/topic/34903-array-hall-of-fame-hard/
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.