我问一个候选人:你喜欢什么?
他的答案是一个数组数学,物理,化学,IT,运动
我确实有一份清单:
在PHP中,使用用户输入获得最大公共标记的作业的最佳方法是什么?
发布于 2015-06-06 11:28:35
使用array_intersect()查找公共标记,然后在返回的标记数量之间进行比较。
$jobs = array(
'software' => array('Math','IT','Programing','Stress','Computer')
'truck' => array('Sports','Driving','Traveling','Exchange')
'physic' => array('Math','Physics','Chemistry','Teaching')
);
$user_tags= array('Math','Physics','Chemistry','IT','Sports');
$max_common = 0;
$desired_job = '';
foreach($jobs as $key=>$job) {
$common = count(array_intersect($job,$user_tags);
if(max_common < $common) {
$desired_job = $key;
$max_common = $common;
}
}https://stackoverflow.com/questions/30682055
复制相似问题