Hi, I have a piece of code that takes a comma delimited text file and prints it line for line. It works brilliantly. Now what I want to do is sort the text file/array so that it prints them in order of the price field eg, £100 then £150 then £300 and so on.
Here is the code as it stands:
code:
$array = file('xfile1.txt');
$anything=array_shift($array);
foreach($array as $row) {
$line = explode('","', $row);
print $line[3] HTML HTML etc etcetc etc
Can you help?
I have tried
code:
<?php
function priceCmp($a, $b){
if ($a[7] == $b[7])return 0;
if ($a[7] < $b[7])return 1;
}
$array = file('xfile1.txt');
$anything=array_shift($array);
uasort($row, priceCmp);
foreach($array as $row) {
$line = explode('","', $row);
ect etc
but this doesnt seem to work. 7 by the way is the 8th thing along the comma delimited line which is the pricce eg, address,dsfsd,dfsdf,dfsedf,sdfsdf,sdfsdf,sdfdsf,PRICE,sfdsdf.
Thanks
Richard