PHP variable variable name containing index
<pre><code>$arr[0]=123;
$a="arr[0]";
echo $$a;
</code></pre>

<p>gives me error </p>

<blockquote>
  <p>Notice: Undefined variable: arr[0]</p>
</blockquote>

<p>on the last line.</p>

<p>What should I do to make it work?</p>

<p><hr/>
EDIT:</p>

<p>Above is the simplification of what I want to do. If someone wants to know why I want to do this, then here's the explanation:</p>

<p>This is something like what I want to do:</p>

<pre><code>if(condition){
    $a=$arr1[0][0];
    $b=$arr1[0][1];
    $c=$arr1[0][2];
}
else{
    $a=$arr2[0];
    $b=$arr2[1];
    $c=$arr2[2];
}
</code></pre>

<p>I can compact it like this:</p>

<pre><code>if(condition)
    $arr=$arr1[0];
else
    $arr=$arr2;
$a=$arr[0];
$a=$arr[1];
$a=$arr[2];
</code></pre>

<p>But I wanted to try doing this using variable variable:</p>

<pre><code>if(condition)
    $arr="$arr1[0]";
else
    $arr="$arr2";
$a={$$arr}[0];
$b={$$arr}[1];
$c={$$arr}[2];
</code></pre>

<p>Sure, we don't <code>need</code> variable variables as we can still code without them. I want to know, for learning PHP, why the code won't work.</p>
