dAivEd Posted December 5, 2009 Report Share Posted December 5, 2009 (edited) Nu taisu spelei 'MuOnline' weblapu, man ir funkcija kura aizvieto class_id, pret nosaukumu, bet sanaak ta ja id ir 14 tad vinsh raada Soul Master4 piemeram, jo paņem tikai 1, nevis 14 id. Rekur funkcija... function class_info($class) { $class_code = array( "0", "1", "2", "16", "17", "18", "32", "33", "34", "48", "49", "50", "64", "65", "66", "80", "81", "82" ); $class_name = array( "Dark Wizzard", "Soul Master", "Grand Master", "Dark Knight", "Blade Knight", "Battle Master", "Fairy Elf", "Muse Elf", "High Elf", "Magic Gladiator", "Duel Master", "Duel Master", "Dark Lord", "Lord Emperor", "Lord Emperor", "Summoner", "Bloody Summoner", "Dimension Master" ); $return = str_replace($class_code, $class_name, $class); return $return; } Kads nevarētu paskaidrot kapēc tā ? Edited December 5, 2009 by dAivEd Quote Link to comment Share on other sites More sharing options...
2easy Posted December 5, 2009 Report Share Posted December 5, 2009 str_replace() strādā pareizi: tā stringā '14' aizvieto '1' -> 'SoulMaster', jo '1' ir pirmais elements no $class_code, kuru str_replace() atrada iekš $class (un aizvietoja ar atbilsotšo elementu no $class_name). līdz ar to jaunais strings ir 'SoulMaster4'. str_replace() visu izdarīja pilnīgi pareizi! ;) pamēģini aiz pašreizējiem masīviem abu pēdējo rindiņu vietā šīs $k = array_search($class, $class_code); if ($k !== false) return $class_name[$k]; bet vispār jau tev pietiktu ar vienu masīvu, kur katra klase ir code => name Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.