Just...Can't...Think...
Okay, guys, I've been working on this for a while now, and I can't figure it out! I've got a directory of files that's plugged into an array, and I'm trying to make a function that will sort them by date. I'm not worried about display right now, as that's been taken care of, but for some reason, I just can't seem to get this to sort properly. It'll sort the first few fine, then just go all wonky.
function sortDate($file_list)
{
$file_list_copy = Array();
for ($i=0; $i[Error: Irreparable invalid markup ('<sizeof($file_list);>') in entry. Owner must fix manually. Raw contents below.]
Okay, guys, I've been working on this for a while now, and I can't figure it out! I've got a directory of files that's plugged into an array, and I'm trying to make a function that will sort them by date. I'm not worried about display right now, as that's been taken care of, but for some reason, I just can't seem to get this to sort properly. It'll sort the first few fine, then just go all wonky.
<lj-cut text="My crappy Code">
<pre>
function sortDate($file_list)
{
$file_list_copy = Array();
for ($i=0; $i<sizeOf($file_list); $i++)
{
$file_list_copy[$i] = $file_list[$i];
}
$array_size = sizeOf($file_list);
//Bubble Sort to arrange items by date Created/modified(Earliest to Latest)
for ($i=0; $i<$array_size; $i++)
{
list($key, $val) = each($file_list);
$i_date = filemtime($val);
for ($j=$i; $j<$array_size; $j++)
{
list($key2, $val2) = each($file_list_copy);
$j_date = filemtime($val2);
if ($i_date > $j_date)
{
$temp = $file_list[$i];
$file_list[$i] = $file_list[$j];
$file_list[$j] = $temp;
} //end if
} //end for
reset($file_list_copy);
} //end for
reset ($file_list);
display($file_list);
} //end sortDate
</pre>
</lj-cut>
Maybe one of you wonderful PHP know-it-all's can help me figure this out. I haven't had the time to work on this as much as I should, and I'm working on what I can divine from the website, but it's just being a righteous pain in the butt.
Any help would be greatly appreciated!
<lj-cut text="My crappy Code">
<pre>
function sortDate($file_list)
{
$file_list_copy = Array();
for ($i=0; $i<sizeOf($file_list); $i++)
{
$file_list_copy[$i] = $file_list[$i];
}
$array_size = sizeOf($file_list);
//Bubble Sort to arrange items by date Created/modified(Earliest to Latest)
for ($i=0; $i<$array_size; $i++)
{
list($key, $val) = each($file_list);
$i_date = filemtime($val);
for ($j=$i; $j<$array_size; $j++)
{
list($key2, $val2) = each($file_list_copy);
$j_date = filemtime($val2);
if ($i_date > $j_date)
{
$temp = $file_list[$i];
$file_list[$i] = $file_list[$j];
$file_list[$j] = $temp;
} //end if
} //end for
reset($file_list_copy);
} //end for
reset ($file_list);
display($file_list);
} //end sortDate
</pre>
</lj-cut>
Maybe one of you wonderful PHP know-it-all's can help me figure this out. I haven't had the time to work on this as much as I should, and I'm working on what I can divine from the website, but it's just being a righteous pain in the butt.
Any help would be greatly appreciated!
