I have the following code which I am trying to compare a title in a csv file & pull back the appropriate price (in the csv) depending on the title:
<a class="Title" href="<?php echo $item->link;?>">
<?php echo $item->title;?> <!--country title-->
</a>
<?php
$pricelist = array();
if (($handle = fopen("townprices.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$pricelist[] = $data;
}
fclose($handle);
}
echo '<pre>'; print_r($pricelist); echo '</pre>';
?>
CSV contents:
Spain, 250
France, 350
Germany, 150
(town/title, price)
This bring back the following array from my csv:
Array
(
[0] => Array
(
[0] => Spain
[1] => 250
)
[1] => Array
(
[0] => France
[1] => 350
)
[2] => Array
(
[0] => Germany
[1] => 150
)
)
What I now need to do is just echo the right price, rather than
echo '<pre>'; print_r($pricelist); echo '</pre>';
So I need to create an if statement, something like:
if $item->title = Spain, print 250
But I am stuck on how to do this. Any help would be appreciated. Thanks
foreach ($pricelist as $value) { ... }?