say i have 4 players with 4 scores,
$player_1_name = 'A', $player_1_score = 5
$player_2_name = 'B', $player_2_score = 1
$player_3_name = 'C', $player_3_score = 8
$player_4_name = 'D', $player_4_score = 5
I need to sort from min to max scores, so to arrange like this:
$player_2_name = 'B', $player_2_score = 1
$player_1_name = 'A', $player_1_score = 5
$player_4_name = 'D', $player_4_score = 5
$player_3_name = 'C', $player_3_score = 8
$arr_scores = array($player_a_score ,$player_b_score ,$player_c_score ,$player_d_score);
sort($arr_scores);
now scores are sorted 1,5,5,8
the challenge for me is to arrange and find player names after sorting scores.
that i must be able to keep player names in another array, then retrieve them via index keys according to new sorted scores 1,5,5,8…
$arr_name = array($player_1_name,$player_2_name,$player_3_name,$player_4_name);
then make sorting to $arr_name, so i can finally retrieve names AND scores like this,
$arr_name[0] // value is 'B';
$arr_name[1] // value is 'A';
$arr_name[2] // value is 'D';
$arr_name[3] // value is 'C';
$arr_scores[0] // value is '1';
$arr_scores[1] // value is '5';
$arr_scores[2] // value is '5';
$arr_scores[3] // value is '8';
of course, in real project, name is not as simple as A,B,C…
how can i sort scores from min to max and then link back each score to respective player?