Answer the question
In order to leave comments, you need to log in
How to sort rows by a specific key?
Such a situation, I'm not strong in algorithms, I need to implement this:
There are lines, you need to sort them by a certain parameter from these lines.
For the input to be:
19:16:30-13.03.17 | Login: Gerard_Muscle
19:16:31-13.03.17 | Login: Hotaru_Nagiwaro
19:16:48-13.03.17 | Login: Gerard_Muscle
19:16:48-13.03.17 | Login: Santa_Moroz
19:17:05-13.03.17 | Login: Gerard_Muscle
19:16:30-13.03.17 | Login: Gerard_Muscle
19:16:48-13.03.17 | Login: Gerard_Muscle
19:17:05-13.03.17 | Login: Gerard_Muscle
19:16:31-13.03.17 | Login: Hotaru_Nagiwaro
19:16:48-13.03.17 | Login: Santa_Moroz
Answer the question
In order to leave comments, you need to log in
we create an array explode("|", $string);
and sort it, I don’t know what kind of lines you have, but I think I’ll convey the essence:
$arr = [];
foreach($lines as $one){
$arr_str = explode("|", $string);
$arr[$arr_str[1]] = $arr_str[0];
}
ksort($arr);
foreach($arr as $key=>$one){
echo $one. '|' .$key;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question