Using PHP version 5.6, MySQL 5.7.
I have been using an array_multisort to sort rows by column. This has been working well sorting by 'apps', followed by 'subapps'. What I wish to do now is combine the values of 'apps' and 'subapps' to sort the column by a new value 'allapps', which would be the sum of 'apps' and 'subapps'.
// GET PLAYER INFO
while($data = $get_players->fetch_assoc())
{
// PLAYER ID
$idt[$i] = $data['id'];
// DETERMINE HOW TO DISPLAY NAME
if($data['firstname'] == '')
{ $names[$i] = $data['lastname']; }
else
{ $names[$i] = $data['firstname'] . ' ' . $data['lastname']; }
$i++;
}
mysqli_free_result($get_players);
// COUNT APPEARANCES
$i=0;
while($data = $get_apps->fetch_assoc())
{
$apps[$i] = $data['apps'];
$i++;
}
mysqli_free_result($get_apps);
// COUNT SUBSTITUTE APPEARANCES
$i=0;
while($data = $get_subapps->fetch_assoc())
{
$subapps[$i] = $data['subapps'];
$i++;
}
mysqli_free_result($get_subapps);
Rather simplistically, this is what I've tried, which doesn't seem to work:
$allapps = $apps + $subapps;
And below is the array_multisort:
array_multisort($allapps, SORT_DESC, SORT_NUMERIC, $apps, $subapps, SORT_DESC, SORT_NUMERIC, $names, $idt);
At the moment, it bypasses $allapps and just continues to sort by $apps, and then $subapps. How best should I combine the values of $apps and $subapps to sort by the combined value of $allapps?
Thank you in advance for any advice.