Skip to content

Instantly share code, notes, and snippets.

@ZerglingGo
Created October 1, 2016 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZerglingGo/f2433a7b3502817283a1eae80aaa7935 to your computer and use it in GitHub Desktop.
Save ZerglingGo/f2433a7b3502817283a1eae80aaa7935 to your computer and use it in GitHub Desktop.
<?php
$name = $_REQUEST['name'];
$info = $_REQUEST['info'];
// $name = ['a', 'b', 'c'];
// $info = [[1, 2, 3],
// [3, 4, 5],
// [1, 2, 1]];
$result = array();
for($i=0; $i<count($name); $i++) {
$total = 0;
$result[$i]['name'] = $name[$i];
for($j=0; $j<count($info[$i]); $j++) {
$result[$i]['score'][] += $info[$i][$j];
$total += $info[$i][$j];
}
$result[$i]['avg'] = $total / count($info[$i]);
}
usort($result, function($a, $b) {
return $a['avg'] - $b['avg'];
});
print_r($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment