Is there a way to access variables in solidity using another variable?
Something like this:
contract Test {
uint age;
string varAge = "age";
function setAge() public {
// varAge should be able to access age variable
${varAge} = 30;
}
}
No. It's not like PHP.
The closest thing I can think of is having a mapping like
mapping(string=>uint) myMap;
. Then you can do stuff likemyMap["abc"] = 123;
You could also do this...