Home >Backend Development >PHP Tutorial > PHP数组比较 求解解决思路
PHP数组比较 求解
这是第一个数组
[code=PHP]
array
0 =>
array
0 => string '1000061 ' (length=7)
1 => string '1000031 ' (length=7)
2 => string '1000056 ' (length=7)
1 =>
array
0 => string '1000056 ' (length=7)
1 => string '1000049 ' (length=7)
3 =>
array
0 => string '1000056 ' (length=7)
1 => string '1000048 ' (length=7)
[/code]
这是第二个数组
[code=PHP]
array
0 => string '1000047 ' (length=7)
1 => string '1000056 ' (length=7)
2 => string '1000061 ' (length=7)
[/code]
第一个数组 和第二个数组 比较 去除不相同的数组元素 还要保留第一个数组的结构
想要的效果是这样的
[code=PHP]
array
0 =>
array
0 => string '1000061 ' (length=7)
1 => string '1000056 ' (length=7)
1 =>
array
0 => string '1000056 ' (length=7)
3 =>
array
0 => string '1000056 ' (length=7)
[/code]
哪位大侠帮我看下
------解决方案--------------------
整理数据的时间比写代码的时间要长得多!
$a = array( 0 => array( 0 => '1000061', 1 => '1000031', 2 => '1000056', ), 1 => array( 0 => '1000056', 1 => '1000049', ), 3 => array( 0 => '1000056', 1 => '1000048', ), ); $b = array( 0 => '1000047', 1 => '1000056', 2 => '1000061', ); foreach($a as &$v) $v = array_intersect($v, $b); print_r($a); <div class="clear"> </div>