eval of array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lasash
Forum Newbie
Posts: 1
Joined: Sun Dec 06, 2009 10:05 am

eval of array

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: eval of array

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply