on topic to your question. With the logic of PHP, the best way I can see this being done is to assign your variable variables outside the array definition:
$id = 1;
$age = 2;
$sort = "id"; // or "age";
$Key = $$sort;
$arr = array($Key => 'string');
print_r($arr);
Which outputs:
Array ( [1] => string )
Though, personally. I'd suggest avoiding this method. It would be best to define your keys explicitly, to assist with backtracing/debugging code. Last thing you want to do, is to be looking through a maze of variable-variables. Especially, if they are created on the fly
Tinkering. I've got this;
$arr[$$sort] = "Value";
print_r($arr);
I've looked into the method to creating a function. I do not see a viable method to do this sucessfully. With the information i've provided (defining out of array definition), hopefully this will steer you in the right direction