konnwat Posted January 19, 2007 Share Posted January 19, 2007 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]<?PHPif (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]<?PHPif (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 More sharing options...
kenrbnsn Posted January 19, 2007 Share Posted January 19, 2007 Take a look at the [url=http://www.php.net/array_keys]array_keys()[/url] function. When you give it a second parameter, the returned array contains all the keys whose value matches that parameter.Ken Link to comment https://forums.phpfreaks.com/topic/34903-array-hall-of-fame-hard/#findComment-164584 Share on other sites More sharing options...
konnwat Posted January 19, 2007 Author Share Posted January 19, 2007 NICE, thats gotta work, thanks ^^ Link to comment https://forums.phpfreaks.com/topic/34903-array-hall-of-fame-hard/#findComment-164608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.