How can I change the $rank
variable name to $rank1
, $rank2
and so on depending on the user $userID
?
foreach($myClient as $users){
$username = $users->usrnm;
$userID = $users->usrID;
$rank...
}
How can I change the $rank
variable name to $rank1
, $rank2
and so on depending on the user $userID
?
foreach($myClient as $users){
$username = $users->usrnm;
$userID = $users->usrID;
$rank...
}
You can do like this:
$userId1 = 1;
$userId2 = 2;
$rankVarName1 = sprintf('rank%s', $userId1);
$rankVarName2 = sprintf('rank%s', $userId2);
$$rankVarName1 = 'rank var value';
$$rankVarName2 = 'other rank';
var_dump($rank1); // rank var value
var_dump($rank2); // other rank
but I recommend you use an array
$ranks = [];
$userId1 = 1;
$userId2 = 2;
$ranks[$userId1] = 'rank var value';
$ranks[$userId2] = 'other rank';
var_dump($ranks[$userId1]); // rank var value
var_dump($ranks[$userId2]); // other rank
U can do it like this:
foreach($myClient as $users){
$username = $users->usrnm;
$userID = $users->usrID;
${'rank'.$userID} = 'something';
}