A newbie question:
I have made a simple bubblesort algorithm to sort an array with time stamps. But I can't get it working, it looks like it goes into a never ending loop.
This is the entire function:
function generate_sorted_entry_array($entries,$timestamps)
{
for ($i = 0; $i < count($entries)-1; $i++)
{
$helparray[] = $i;
}
$arraychanged = 1;
$forbool = 0;
while ($arraychanged)
{
$arraychanged = 0;
$forbool = 0;
//The problem seems to be in this loop.
for ($c = 0; $c < count($timestamps)-2; $c++)
{
if ($timestamps[$c] > $timestamps[$c+1])
{
$temptime = $timestamp[$c];
$timestamp[$c] = $timestamp[$c+1];
$timestamp[$c+1] = $temptime;
$temphelp = $helparray[$c];
$helparray[$c] = $helparray[$c+1];
$helparray[$c+1] = $temphelp;
$forbool = 1;
}
}
$arraychanged = $forbool;
}
for ($i = 0; $i < count($helparray)-1; i++)
{
$index = $helparray[$i];
$resultarray[] = $entries[$index];
}
return $resultarray;
I've probably overlooked something.
Thank you for your help.
Eddie