I need to order an array using usort based on a string of text that comes from a mysql call using php4.
So far I have the mysql call to get the order:
$result=mysql_query("SELECT rank from order WHERE id=1");
$row = mysql_fetch_row($result);
this gives me something like $row[0]='Alberto, Carlos, Brocephus, Edgar, Daniela';
And I have the function, which works if I hard code in an array:
function cmp($a,$b){
//$order = how do I get $row[0] in here?
$a_index = array_search($a['name'], $order);
if (!$a_index) {
$a_index = 999;
}
$b_index = array_search($b['name'], $order);
if (!$b_index) {
$b_index = 999;
}
return $a_index - $b_index;
}
usort($names,cmp);
What's the simplest way to get that string into the cmp function as an array?