php – 如何从数组中删除不在另一个数组中的键?
发布时间:2020-12-13 17:51:06 所属栏目:PHP教程 来源:网络整理
导读:我有以下两个数组: EDIT On suggestion from @Wrikken I’ve cleaned the first array and now have this: 第一阵列: Array( [0] = 3 [1] = 4 [2] = 9 [3] = 11) 第二阵列: Array( [3] = stdClass Object ( [tid] = 3 ) [12] = stdClass Object ( tid] =
我有以下两个数组:
第一阵列: Array ( [0] => 3 [1] => 4 [2] => 9 [3] => 11 ) 第二阵列: Array ( [3] => stdClass Object ( [tid] => 3 ) [12] => stdClass Object ( tid] => 12 ) [9] => stdClass Object ( [tid] => 9 ) )
所以我最终应该: Array ( [3] => stdClass Object ( [tid] => 3 ) [9] => stdClass Object ( [tid] => 9 ) )
你可以这样做:
$keys = array_map(function($val) { return $val['value']; },$first); $result = array_intersect_key(array_flip($keys),$second);
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |