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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.