I've looked on Stack Overflow with no solution that seems to work. Know that I'm a newbie!
Suppose I have a file (data.csv) with the following contents:
year,total
1990,57.58
2011,73.28
1880,54.67
1996,53.41
1950,53.22
1979,52.76
1876,52.62
1883,52.35
1882,52.12
2018,52.23
...then import the data with PHP:
$csv = array_map('str_getcsv', file('data.csv'));
How would I sort both the year and total by the total column in ascending order (such that 1882/52.12 are under $csv[0] in the array and 2011/73.28 are under $csv[10]?
The following and a print($csv); does not seem to be getting the items in the right order:
function compare($a, $b) {
return ($b[0][1] - $a[0][1]);
}
usort($csv, "compare");
Do I need to use typecasting? Thank you!