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";
??????? }
}
?>

Reply via email to