I have the following code: // check if the file exists if (file_exists ('sys/data/online.txt')) { $read = file ('sys/data/online.txt'); // read the online file foreach ($read as $line) { $item = explode ("\t", $line); if (isset ($end_data)) { $end_data .= $this-> disp_name ($item[0]) . '<br />'; } else { $end_data = $this-> disp_name ($item[0]) . '<br />'; } } if (isset ($end_data)) { return $end_data; } } PHP: It makes an array from a file by lines, then makes another array by separating each array item into another array with tabs. I want to order the names by the timestamp. How would I go about doing this. I have no idea how to even start this.
would probably just order by dumping it into a db and letting that do it for me. if it's a pure linux timestamp though, can just use a bubblesort / any of the sorting algorithms to do it
Ok I figured it out. I had to change my previous code to this: // check if the file exists if (file_exists ('sys/data/online.txt')) { $read = file ('sys/data/online.txt'); // read the online file foreach ($read as $line) { $item = explode ("\t", $line); if (!isset ($end_data)) { $end_data = array(); } $end_data[$item[1]] = $this-> disp_name ($item[0]); } if (isset ($end_data)) { ksort ($end_data); $end_data = array_reverse ($end_data); foreach ($end_data as $key => $disp_name) { if (isset ($result)) { $result .= '<li>' . $disp_name . '</li>'; } else { $result = '<li>' . $disp_name . '</li>'; } } return '<ul class="onlinelist">' . $result . '</ul>'; } } PHP: