When you use $$string[0], you are calling a variable named in an array called $string. Since strings are basically complicated array-like objects, you are calling the character at position 0. So basically, the effect you get is:
$string = "temp";
$$string = array();
$$string[0] = "prova";
var_dump($t);
because the reference for $string[0] is the first character in the string "temp", or "t", so you are really just calling $t. What you need is ${$string}[0].
If you want the variable to be an array:
$var_name = "some_var";
${$var_name} = array();
${$var_name}[0] = "some value";
${$var_name}[1] = "another value";
var_dump(${$var_name});
If you want your name of your variable to be an array:
$var_names = array();
$var_names[0] = "some_var";
$var_names[1] = "another_var";
${$var_names[0]} = "some value";
${$var_names[1]} = "another value";
var_dump(${$var_names[0]});
var_dump(${$var_names[1]});
The first is an example of what I think you were trying to do. The second is an example of what you were actually doing.
Or, you could just use an associative array:
$my_vars = [
"some_var" => "some value",
"another_var" => "another value",
];
var_dump($my_vars);
//or loop
foreach ($my_vars as $key => $value)
{
var_dump($my_vars[$key]);
//or echo
echo $key . ": " . $value . "<br>";
//or set
$my_vars[$key] = "new calculated value + " . $value;
}
var_dump($my_vars);
${$string[0]} = "prova";See: php.net/manual/en/migration70.incompatible.php${$string}[0] = "prova";