I have a repeating code in php that I would imagine I can somehow condense into a function and simply call the function multiple times. I tried doing this and nothing appears to happen. This is on repetition of the old code:
if ($health_1 > $health_2) {
$health_left = '#7fba00';
$health_right = '#e81123';
} else if ($health_perlvl_1 == $health_perlvl_2) {
$health_left = '#0451ff';
$health_right = '#0451ff';
} else {
$health_left = '#e81123';
$health_right = '#7fba00';
}
and this repeats about 12 times with other stats. I decided to try to condense it to this:
function stat_color($stat_1,$stat_2,$color_left,$color_right) {
if ($stat_1 > $stat_2) {
$color_left = '#7fba00';
$color_right = '#e81123';
} else if ($stat_1 == $stat_2) {
$color_left = '#0451ff';
$color_right = '#0451ff';
} else {
$color_left = '#e81123';
$color_right = '#7fba00';
}
}
stat_color($health_1,$health_2,$health_left,$health_right);
But the colors are not there later when they are needed. Is there any way to actually get this to work?
return(array('left' => '#7fba00', 'right' => '#e81123'));or similar.return $color_left;andreturn $color_right;at the end and that did nothing. I'm not really sure how that array works