I'm trying to perform the same function dosomething()
to multiple variables $lastsum $avatar $angels $city $square
in PHP.
$lastsum->dosomething();
$avatar->dosomething();
$angels->dosomething();
$city->dosomething();
$square->dosomething();
Is there a way to make this code cleaner by listing the names of the variables in a string array and perform the function with a for loop. I'm looking for something like this. Does anyone know the right way to do this in PHP?
$all = ['lastsum' , 'avatar', 'angels' , 'city' , 'square'];
foreach (....){
$(nameofvariable)->dosomething();
}