在PHP中比较数组以生成键数组

在PHP中比较数组以生成键数组,php,arrays,key,Php,Arrays,Key,我有一个问题,我确信用PHP的内置函数或一两行代码很容易解决,但我似乎无法用我有限的经验找到解决方案 我有一个主阵列: $master_array = ('location_1','location_2','location_3','location_4','location_5'); 我得到一个数组: $submitted_array = ('location_1','location_3'); 我需要比较两个数组以形成如下数组: $locations = (0,2); 其中,$loca

我有一个问题,我确信用PHP的内置函数或一两行代码很容易解决,但我似乎无法用我有限的经验找到解决方案

我有一个主阵列:

$master_array = ('location_1','location_2','location_3','location_4','location_5');
我得到一个数组:

$submitted_array = ('location_1','location_3');
我需要比较两个数组以形成如下数组:

$locations = (0,2);
其中,$locations数组中的数字是$master_数组中$submitted_数组元素的位置

当然,一定有一种没有循环的方法

$result = array_keys(array_intersect($master_array , $submitted_array));
print_r($result);
$locations = array_keys(array_intersect($master_array, $submitted_array));