Page 1 of 1

eval of array

Posted: Sun Dec 06, 2009 10:08 am
by lasash
Hi All

I'm trying this:

Code: Select all

 
            for ($k=0; $k<$table_cols; $k++)
                {
                 $v="\$arr$k[]=\$my_item$k;\n";
                 eval("$v");
                }
 
and it gives me this:

Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/dhlasash/public_html/crawler/test.php on line 56

Anybody knows why?

Re: eval of array

Posted: Sun Dec 06, 2009 1:58 pm
by AbraCadaver
I'm positive there's a much better way to do what you are trying to accomplish, but to answer your question, try:

Code: Select all

$v = '$arr' . $k . '[] = $my_item' . $k;
-Shawn