I have this laid out:

1-Mike|
2-Jane|
3-Brad|
4-Kelly|

How do I have the output sort in ASC order based on the name first, then the id? It currently sorts based on how it was originally laid out.

Here's what I have.

function class($students) {

$students = explode("|",$students);

$students_cnt = count($students);
$i=0;

unset($opt);

while($i<$students_cnt) {

$opt_arr = explode("-",$students[$i]);
if((int)$opt_arr[0] && $opt_arr[1])$opt .= "<option value=\"".$opt_arr[0]."\">".$opt_arr[1]."</option>\n";
$i++;

}

return $opt;

}

    Yes by alphabetical order

      [man]usort[/man] or [man]array_multisort[/man]. If you're using usort, the comparison function would compare the names, and return <0 or >0 if they're different; if they're the same it would compare the ids and return <0 or >0 if they're different. If they're still the same, then it would return 0.

        I don't think my brain is working anymore with the lack of sleep but I'm still very lost on this part. How would I be able to sort this variable to have it alphabetically order by letter and not number?

        $keywords = "
        1,jane;
        2,jordan;
        3,david;
        4,mike;
        5,tony;
        6,britney;";
        
        Output:
        6,britney;
        3,david;
        1,jane;
        2,jordan;
        4,mike;
        5,tony;
        
          Write a Reply...