Jump to content

Recommended Posts

<?php
if($data['cclass'] == "Warrior") {
    return '<span style="color:#C79C6E;">'.$input.'</span>';
} elseif($data['cclass'] == "Paladin") {
    return '<span style="color:#F58CBA;">'.$input.'</span>';
} elseif($data['cclass'] == "Hunter") {
    return '<span style="color:#ABD473;">'.$input.'</span>';
} elseif($data['cclass'] == "Rogue") {
    return '<span style="color:rgb(255,245,105);">'.$input.'</span>';
} elseif($data['cclass'] == "Priest") {
    return '<span style="color:#FFFFFF;">'.$input.'</span>';
} elseif($data['cclass'] == "Death Knight") {
    return '<span style="color:#C41F3B;">'.$input.'</span>';
} elseif($data['cclass'] == "Shaman") {
    return '<span style="color:#0070DE;">'.$input.'</span>';
} elseif($data['cclass'] == "Mage") {
    return '<span style="color:#69CCF0;">'.$input.'</span>';
} elseif($data['cclass'] == "Warlock") {
    return '<span style="color:#9482C9;">'.$input.'</span>';
} elseif($data['cclass'] == "Druid") {
    return '<span style="color:#FF7D0A;">'.$input.'</span>';
}
?>

 

I used to be able to majorly simplify this kind of thing but ive forgotten, any help would be v nice :)

Link to comment
https://forums.phpfreaks.com/topic/241001-how-can-i-simplify-something-like-this/
Share on other sites

<?php
if($data['cclass'] == "Warrior") {
    return '<span style="color:#C79C6E;">'.$input.'</span>';
} elseif($data['cclass'] == "Paladin") {
    return '<span style="color:#F58CBA;">'.$input.'</span>';
} elseif($data['cclass'] == "Hunter") {
    return '<span style="color:#ABD473;">'.$input.'</span>';
} elseif($data['cclass'] == "Rogue") {
    return '<span style="color:rgb(255,245,105);">'.$input.'</span>';
} elseif($data['cclass'] == "Priest") {
    return '<span style="color:#FFFFFF;">'.$input.'</span>';
} elseif($data['cclass'] == "Death Knight") {
    return '<span style="color:#C41F3B;">'.$input.'</span>';
} elseif($data['cclass'] == "Shaman") {
    return '<span style="color:#0070DE;">'.$input.'</span>';
} elseif($data['cclass'] == "Mage") {
    return '<span style="color:#69CCF0;">'.$input.'</span>';
} elseif($data['cclass'] == "Warlock") {
    return '<span style="color:#9482C9;">'.$input.'</span>';
} elseif($data['cclass'] == "Druid") {
    return '<span style="color:#FF7D0A;">'.$input.'</span>';
}
?>

 

I used to be able to majorly simplify this kind of thing but ive forgotten, any help would be v nice :)

 

Maybe this is usefull ?  http://php.net/manual/en/control-structures.switch.php

EDIT: Basically the same as what PFMaBiSmAd said ^^^

 

Storing the values in an array, and using the array element's value to fill in the color: attribute would reduce the amount of code, if that's your goal.

 

$classes = array( 'Warrior' => '#C79C6E', 'Paladin' => '#F58CBA', 'Hunter' => '#ABD473'); // Etcetera.

return "<span style=\"color:{$classes[$data['cclass']]};\">$input</span>";

Ahh guys, thankyou very much..

I did try the switch method but turned out just as bulky as individual if statements..

 

The array is what I was looking for :)

 

Thanks again all who replied for your effort :D

 

<?php
$classes = array( 'Warrior' => '#C79C6E', 'Paladin' => '#F58CBA', 'Hunter' => '#ABD473', 'Rogue' => 'rgb(255,245,105)', 'Priest' => '#FFFFFF',
	            'Death Knight' => '#C41F3B', 'Shaman' => '#0070DE', 'Mage' => '#69CCF0', 'Warlock' => '#9482C9', 'Druid' => '#FF7D0A');

return "<span style=\"color:{$classes[$data['cclass']]};\">$input</span>";
?>

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.