Is there any situation where an array
is not suitable but a variable variable
is? I cannot think of one or find one on any Stack Programmer Q&A.
<?php
$foo = array();
for($i = 0;$i < 3; $i++){
$foo[$i] = "bar ".$i;
}
var_dump($foo); // ["bar 0", "bar 1", "bar 2"]
for($i = 0;$i < 3; $i++){
$foo = "bar".$i;
$$foo = "baz ".$i;
}
echo $bar0; //baz 0
echo $bar1; //baz 1
echo $bar2; //baz 2
?>