Jump to content
php.lv forumi

par str_replace


dAivEd

Recommended Posts

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 by dAivEd
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...