How to assign variable dynamically to php list function
<p>What I am doing that I want to generate a list based on how many items are in an array, so I have counted the items and loop over them, create a number based var and construct a string $var which contains $a1,$a2.... and assigns the $var to list list($var)</p>

<p>and tried to access $a1 but it gives me the error "Undefined variable: a1"</p>

<p>Is there any other way to do it?</p>

<p>Here is my code: </p>

<pre><code>$arr = array('1','2','3');
$listsize = count($arr);
$var='';
for($i=1;$i&lt;=$listsize;$i++){
        $var.='$a'.$i;
        if($i!=$listsize){
            $var.=',';
        }
}

list($var) = $arr;
echo $a1;
</code></pre>
