I have some variables like this:
$barbarian = 7;
$archer = 7;
$giant = 7;
And a function like this:
function army($troopData,$troop,$thing){
if(isset($troop) && $troopData+1 == ${"$thing"}){
$troopData++;
$text = "<span class='army-icon active top-lvl $thing-icon'><span>$troopData</span></span>";
}elseif(isset($troop)){
$troopData++;
$text = "<span class='army-icon active $thing-icon'><span>$troopData</span></span>";
}else{
$text = "<span class='army-icon $thing-icon'><span></span></span>";
}
return $text;
}
Notice the first if:
if(isset($troop) && $troopData+1 == ${"$thing"}){
The function is called like this:
army($troopslvl4000000,$troops4000000, "barbarian");
army($troopslvl4000001,$troops4000001, "archer");
The last parameter is named $thing in the function.
So I need to first line of the if to check if:
1) $troop is set.
2) $troopData+1 == $barbarian (or whatever thing is. $archer for the second function call)
But it isn't working. It is always using the elseif or the else. The first if never gets called...
${"$thing"}supposed to be? That doesn't look like valid PHP to me$varname = archerand$archer = 5then$$varname = 5${"$thing"}notation is also correct, as is$$thing. I think the issue is the lack of theglobalstatements as in my answer.${"$variable"}syntax before. Thanks for the explanation!