array('ost','tomat','skinke','oksekød','ananas'), 'pizza 2' => array('ost','tomat','bacon','kapers','salat'), 'pizza 3' => array('tomat','salat','ananas') ); function find_best_matches($pizzas, $included, $excluded = array()) { $result = array(); foreach($pizzas as $name => $ingredients) { if(count(array_intersect($ingredients, $excluded)) === 0) { $score = count(array_intersect($ingredients, $included))/count($included); if($score > 0) { $result[$name] = $score; } } } arsort($result); return $result; } function test($included, $excluded = array()) { global $pizzas; $result = find_best_matches($pizzas, $included, $excluded); echo implode('+',$included) . ":\r\n"; foreach($result as $pizza => $score) { echo "$pizza : $score\r\n"; } } test(array('ost','tomat')); test(array('tomat')); test(array('ost','tomat','skinke')); test(array('ost','tomat','skinke','bacon','oksekød','ananas')); test(array('ost','skinke','bacon')); test(array('ost','skinke','bacon'), array('ananas')); ?>