Jump to content

Help with a switch


zelig

Recommended Posts

Here is my dilemma.

 

I'm trying to get the "class name" to return instead of the number that is associated with it.

 

I wrote a switch so that each of the 16 cases would be associated with what the class name is.

 

However, how do I make it output into my statement?

 

Here is what I have so far:

 

function getClassByNumber($x){
switch($x){
case 1: return "Alchemist";
case 2: return "Assassin";
case 3: return "Dark Arts";
case 4: return "Dark Paladin";
case 5: return "Entertainer";
case 6: return "Hunter";
case 7: return "Mage";
case 8: return "Monk";
case 9: return "Paladin";
case 10: return "Pirate";
case 11: return "Priest";
case 12: return "Psion";
case 13: return "Scholar";
case 14: return "Thief";
case 15: return "Warlock";
case 16: return "Warrior";
}
}

$class = getClassByNumber($username->class);

echo You are now a $class.

 

Username is defined as seeking the table I want. Class is the field where the number is stored.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/251926-help-with-a-switch/
Share on other sites

Here is my dilemma.

 

I'm trying to get the "class name" to return instead of the number that is associated with it.

 

I wrote a switch so that each of the 16 cases would be associated with what the class name is.

 

However, how do I make it output into my statement?

 

Here is what I have so far:

 

function getClassByNumber($x){
switch($x){
case 1: return "Alchemist";
case 2: return "Assassin";
case 3: return "Dark Arts";
case 4: return "Dark Paladin";
case 5: return "Entertainer";
case 6: return "Hunter";
case 7: return "Mage";
case 8: return "Monk";
case 9: return "Paladin";
case 10: return "Pirate";
case 11: return "Priest";
case 12: return "Psion";
case 13: return "Scholar";
case 14: return "Thief";
case 15: return "Warlock";
case 16: return "Warrior";
}
}

$class = getClassByNumber($username->class);

echo You are now a $class.

 

Username is defined as seeking the table I want. Class is the field where the number is stored.

 

Thanks!

 

echo "You are now a $class.";

Link to comment
https://forums.phpfreaks.com/topic/251926-help-with-a-switch/#findComment-1291719
Share on other sites

You could also use a "lookup" array.

 

$class = array( 1 => "Alchemist", "Assassin", "Dark Arts", "Dark Paladin", "Entertainer", "Hunter", "Mage", "Monk", "Paladin", "Pirate", "Priest", "Psion", "Scholar", "Thief", "Warlock", "Warrior" );
echo "You are now a " . $class[$username->class];

Link to comment
https://forums.phpfreaks.com/topic/251926-help-with-a-switch/#findComment-1291724
Share on other sites

I can't seem to get the lookup array to work with what I'm doing.

 

Here is the statement that I'm using instead of just the plain echo.

 


$dString = "The $class $peepr known as $button<a href=main.php?username=$username&password=$password&action=look+at+$peeps[$i] $overlib>$thepeepname</a> is here$d<br>\n";

 

I don't know how to add the array lookup where $class is and still have it work correctly...

Link to comment
https://forums.phpfreaks.com/topic/251926-help-with-a-switch/#findComment-1291726
Share on other sites

Assuming it's $username->class like in your post above, using {complex notation} should do it.

 

$dString = "The {$class[$username->class]} $peepr known as $button<a href=main.php?username=$username&password=$password&action=look+at+$peeps[$i] $overlib>$thepeepname</a> is here$d<br>\n";

Link to comment
https://forums.phpfreaks.com/topic/251926-help-with-a-switch/#findComment-1291729
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.