Click to See Complete Forum and Search --> : sorting problems


DeadKennedy
02-26-2004, 06:30 PM
ok, i have a txt file named convosarray.txt where a typical line looks like this

date||name||filename||rating||user||participants||description

in my php file, i load the file into an array with file() after that i explode each line by "||" i want to sort every line by something the user defines (sort each line by date, or name, or filename, ect...) I'm not sure how to go about doing this

heres what i have so far... it doesn't work, but it may help somehow:
$sort = $_GET['sort'];

$convos = file("convosarray.txt");

$d = 0;
while($convos[$d] !== end($convos)){
$convos[$d] = explode("||", $convos[$d]);
$d++;
}
$convos[$d] = explode("||", $convos[$d]);
if(!isset($sort)){
$sort = "0";
}

$d = "0";
$others = array("0", "1", "2", "3", "4", "5", "6");
unset($others[$sort]);
$others = implode("::::", $others);
$others = explode("::::", $others);
while($convos[$d] !== end($convos)){
$convosb[$d] = $convos[$d];
$convos[$d] = array (
$convos[$d][$sort],
$convos[$d][$others[0]],
$convos[$d][$others[1]],
$convos[$d][$others[2]],
$convos[$d][$others[3]],
$convos[$d][$others[4]],
$convos[$d][$others[5]]
);
$d++;
}
$convosb[$d] = $convos[$d];
$convos[$d] = array (
$convos[$d][$sort],
$convos[$d][$others[0]],
$convos[$d][$others[1]],
$convos[$d][$others[2]],
$convos[$d][$others[3]],
$convos[$d][$others[4]],
$convos[$d][$others[5]]
);
arsort($convos);

Khalid Ali
02-26-2004, 08:28 PM
Thisnk this link will help you
http://www.php.net/manual/en/function.ksort.php