I have a csv file (test.csv) like this (no header)
name2,age23,city5
name5,age55,city3
name3,age36,city4
name1,age18,city2
name4,age44,city1
I want to sort on name column like this ascending or descending order
name1,age18,city2
name2,age23,city5
name3,age36,city4
name4,age44,city1
name5,age55,city3
<?php
if (($handle = fopen("test.csv", "r")) !== FALSE) {
$i=1;
$row=0;
$csv_row = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$csv_row = $data;
?>
<tr>
<td><?php echo $i;?> </td>
<td><?php echo $csv_row[1];?></td>
<td><?php echo $csv_row[2];?></td>
<td><?php echo $csv_row[3];?></td>
</tr>
<?php $i++;
}
fclose($handle);
}
?>
How to sort data ($csv_row) on a column (Name) before print? Suggested answer is not working for me.
I am new in php. Many suggestion available but they are not working properly . Please give a simple solution. Thanks in advance.