Variable varialbe with array not working

From: Date: Thu, 01 May 2008 01:24:15 +0000
Subject: Variable varialbe with array not working
Groups: php.general 
Request: Send a blank email to php-general+get-273748@lists.php.net to get a copy of this message
I am trying to use variable variables in an array. ?The last line of code does not work. ?More specifically the last variable in the last line of code does not work in this setup. ?The array gets created with the appropriate indexes however the values are blank. ?I can echo item_value and it contains a string by the time it gets to that line. ?If I use text instead of a variable for the value it works. ?Is my code wrong or could this be a bug? The file that is read has the following format: item_1_name= Dummy Text 1 item_1_price=10 item_1_date=Jan 10-14, 2008 item_2_name=Dummy Text 2 item_2_price=20 item_2_date=Feb 1-5, 2008 <?php $info = file("info.txt"); foreach($info as $line) { ??????? if (substr($line,0,1) != "#" && trim($line) != "") { ??????????????? list($item_name, $item_value) = explode("=", $line); ??????????????????????? if (substr($item_name,6) == "_") { ??????????????????????????????? $item_num = substr($item_name,0,5); ??????????????????????? } else { ??????????????????????????????? $item_num = substr($item_name,0,6); ??????????????????????? } ??????????????????????? $item_index = str_replace("_","",(strrchr($item_name,"_"))); ??????????????????????? ${$item_num}[$item_index] = "$item_value"; ??????? } } ?>

« previous php.general (#273748) next »