In PHP 5, you should write
echo ${$variablename}[$key];
The reason why the code in your question works in PHP 7 is that PHP 7 introduced changes in how it handles indirect variables:
Indirect access to variables, properties, and methods will now be evaluated strictly in left-to-right order, as opposed to the previous mix of special cases. The table below shows how the order of evaluation has changed.
More specifically, the following expression:
$$foo['bar']['baz']
Was interpreted in PHP 5 as:
${$foo['bar']['baz']}
And in PHP 7:
($$foo)['bar']['baz']
Source: http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect