So I am trying to find the best model within our database to match the user's inputted values for Height, Weight, etc. I have generated a variable called heightMatchMultiple based on weighted values and stored all the results in a global array $models. How can I apply math to only the ____MatchMultiple fields and then sort by the result? For example, I store the modelID of each model but I only want to add up the other values and then find the highest average.
Here is some relevant code:
while($row=mysqli_fetch_array($array))
{
$userHeight=$_POST['height'];
$userWeight=$_POST['weight'];
$userShoulder=$_POST['shoulder'];
$userWaist=$_POST['waist'];
$userInseam=$_POST['inseam'];
$heightMatchMultiple=0;
//creates a weighted variable for height
if(isset($row['modelHeight']))
{
if($userHeight==$row['modelHeight'])
{
$heightMatchMultiple=10;
}
elseif($userHeight==($row['modelHeight']+1) || $userHeight==($row['modelHeight']-1))
{
$heightMatchMultiple=9;
}
//same code down til multiple hits 1
else
{
$heightMatchMultiple=1;
}
//similar code for the weight, shoulders, etc.......
//....
array_push($models,array("modelID" => $row['modelID'],
"modelHeightMatch" => $heightMatchMultiple,
"modelWeightMatch" => $weightMatchMultiple,
"modelShoulderMatch" => $shoulderMatchMultiple,
"modelWaistMatch" => $waistMatchMultiple,
"modelInseamMatch" => $inseamMatchMultiple));
I would like to make a function that adds all of the _____MatchMultiple variables within the array (not including modelID) and then divides by the number of items within the array for each. This way I can find out which model is the closest match.