<?php
// Open the file
$filename = 'pvemail.txt';
$fp = fopen($filename, 'r');
// Add each line to an array
if ($fp) {
$array = explode("\n", fread($fp, filesize($filename)));
}
//print_r ($array);
for ($c = 0; $c < count($array); $c++){
$cell = explode(",", $array[$c]);
//print_r ($cell);
if ($cell[3] == 'ACTIVE')
{
echo $cell[2].' - '.$cell[12].' '.$cell[11];
echo '<br/>';
}
}
?>
This code takes a CSV file, reads it and the first if statement explodes each line of the file into its own array. The for loop the explodes each of these lines into arrays made up of 20 key=>value pairs. The second if statement then loops through these pairs to extract and print to the screen the three pairs that I want.
The problem I'm having is I now want the data to be sorted alphabetically, and so far no matter what sort() function I use, or where I put it, nothing happens.
I tried to use sort($cell)
between the for loop and the second if loop and nothing happened, I tried using the same code inside, and after, the if loop and nothing happened, I've tried moving the $cell array to another array and sorting that, I've tried ksort($cell
, asort($cell)
, I've even tried passing the array to JavaScript and sorting it that way and nothing is happening!
I'm starting to pull my hair out here, is there anything obvious that I'm missing or not doing that's stopping the sort working?