List Array Values from TXT that have a Common Variable
Posted: Wed Jul 29, 2009 8:17 pm
Hello. Below is a list I have that is using a common variable throughout every array.
This is for a project where depending on what value the code calls for, it inserts the appropriate title and description. So my arrays need to keep the same variable ($myvar) for every line like listed above. Now this functions perfectly, but is not relevant to my question. I only mention it to mate not that I cannot use different varabile names for each line.
Okay, my question... In another page on the site I am wanting to have a list that will show all lines of the txt file. For example, it would appear like:
Title of Value_a Description for Value_a
Title of Value_b Description for Value_b
...and so on.
In my mind, I am thinking the code would be sometihng like this:
...so that it would echo the title and description of line 1 plus a <br />, then echo the title and description of line 2 plus a <br />, and continue. However, it does not work. Also note that this text file will constantly have new lines of arrays added weekly so the PHP cannot simply say "echo the data on line 1, then line 2" specifically. It has to do it in the way that it simply says pull the top line and continues down the list until it completes the list regardless of whether it totals 10 lines or 100 lines.
Would someone more knowledgeable of PHP be able to see a quick fix to this solution? If you need further info, let me know, and thanks in advance.
Code: Select all
$myvar[value_a] = array('title'=> 'Title of Value_a', 'description' => 'Description for Value_a');
$myvar[value_b] = array('title'=> 'Title of Value_b', 'description' => 'Description for Value_b');
$myvar[value_c] = array('title'=> 'Title of Value_c', 'description' => 'Description for Value_c');
$myvar[value_d] = array('title'=> 'Title of Value_d', 'description' => 'Description for Value_d');
$myvar[value_e] = array('title'=> 'Title of Value_e', 'description' => 'Description for Value_e');
$myvar[value_f] = array('title'=> 'Title of Value_f', 'description' => 'Description for Value_f');This is for a project where depending on what value the code calls for, it inserts the appropriate title and description. So my arrays need to keep the same variable ($myvar) for every line like listed above. Now this functions perfectly, but is not relevant to my question. I only mention it to mate not that I cannot use different varabile names for each line.
Okay, my question... In another page on the site I am wanting to have a list that will show all lines of the txt file. For example, it would appear like:
Title of Value_a Description for Value_a
Title of Value_b Description for Value_b
...and so on.
In my mind, I am thinking the code would be sometihng like this:
Code: Select all
$allarrays = "thearrayfile.txt";
$lines = file($allarrays);
foreach ($lines as $line)
{
echo ($myvar[]['title'].$myvar[]['description'].'<br />');
}Would someone more knowledgeable of PHP be able to see a quick fix to this solution? If you need further info, let me know, and thanks in advance.