I am doing a school project where I have to open a txt file and acess a list of furniture and their prices. The following is the format;
Dining Table, 595.00
Dining Chair, 145.00
Coffee Table, 259.99
I want to basically put them into an associative array with keys and values that I can acess to, so I can quickly calculate the prices of what the customers ordered and the quantity.
$filename = "Furniture.txt";
$myfile = fopen($filename, "r") or die("Unable to open file!");
while(!feof($myfile)) {
$data = array(fgets($myfile)."<br>");
}
$IDArray = array();
foreach($data as $line)
{
$pieces = explode(',',$line);
$IDArray[$pieces[0]] = $pieces[1];
}
foreach ($IDArray as $IDNumber =>$Price) {
echo "Furniture: ".$IDNumber. '<br>';
echo "Price: ".$Price. '<br>';
echo "<br>";
var_dump($data);
This was my attempt but when I try to echo..it only comes up with the last key and pair and not all of the content.