我有一些索引需要从主数组中删除.例如:
$removeIndex=array(1,3,6); $mainArray=array('1'=>'a','2'=>'b','3'=>'c','4'=>'d','5'=>'e','6'=>'f');
我想要最终结果如:
$mainArray=array('2'=>'b','5'=>'e');
也许尝试array_diff_key:
$removeIndex=array(1,'6'=>'f'); $removeIndex = array_flip($removeIndex);//flip turns values into keys echo '<pre>'; //compute diff between arr1 and arr2,based on key //returns all elements of arr 1 that are not present in arr2 print_r(array_diff_key($mainArray,$removeIndex)); echo '</pre>';
当我尝试这个时,它返回:
Array ( [2] => b [4] => d [5] => e )