Forum Moderators: coopster
$employers = array(
'employer id' => array('values', 'for', 'each', 'question');
'employer id' => array('values', 'for', 'each', 'question');
);
$workers = array(
'worker id id' => array('values', 'for', 'each', 'question');
'worker id id' => array('values', 'for', 'each', 'question');
);
foreach($workers as $worker => $w_answers) {
$w_total = array_sum($w_answers);
foreach($employers as $employer => $e_answers) {
$e_total = array_sum($e_answers);
if($e_total <= $w_total) {
$diff = $w_total - $e_total;
} else {
$diff = $e_total - $w_total;
}
$final[$worker][$employer] = $diff;
}
asort($final[$worker]);
}
$output = '<u>Best matches:</u>';
foreach($workers as $worker => $ignore) {
$diff = $final[$worker][0];
$best_match = array_search($diff, $final[$worker]);
$output .= '<br />' . $worker . ' => ' . $best_match;
}
echo $output;