I have a variable $var
that can only be set to, let's say, a
or b
. I have two global arrays, e.g. $aNames
and $bNames
. Finally there's also a variable $number
. To bring everything together, I'd like to combine the values to get an element from the array.
Example:
$var = 'a';
$number = 2;
$el = "$$var"."Names[".$number."]";
$el == $aNames[2] // true
But I'm not sure how to write that first $el
line without it being interpreted as a string.