我有两个多维数组我想只拿那些数组 键值与第一个数组不同
这是我的两个数组:
$array1 = Array
(
[0] => Array
(
[id] => 1
[serial] => k-0001
[u_rec_id] => 1
[employer_office] => uouuououou
[job_type] => ouuou
[job_title] => u
[job_appointment_date] => 2013-07-15
[job_duration] => ouu
)
[1] => Array
(
[id] => 2
[serial] => k-0001
[u_rec_id] => 1
[employer_office] => DDC
[job_type] => Manger
[job_title] => Manager
[job_appointment_date] => 2013-07-17
[job_duration] => one year
)
)
这是我的第二个数组
$array2 = Array
(
[0] => Array
(
[id] => 1
[serial] => k-0001
[u_rec_id] => 1
[employer_office] => uouuououou
[job_type] => ouuou
[job_title] => u
[job_appointment_date] => 2013-07-15
[job_duration] => ouu
)
[1] => Array
(
[id] => 2
[serial] => k-0001
[u_rec_id] => 1
[employer_office] => ouo
[job_type] => uououo
[job_title] => udds
[job_appointment_date] => 2013-07-17
[job_duration] => uo
)
);
我尝试过array_diff和array_diff_assoc它也不适用于我 我收到此错误
遇到PHP错误
严重性:注意
消息:数组到字符串转换
文件名:history / home.php
行号:729
答案 0 :(得分:0)
这样的事情可以让你在那里,取决于你想要什么:
$diff = array_udiff($array1, $array2, function (array $a, array $b) {
return (int)array_diff($a, $b);
});
调整比较功能以比较您想要比较的确切内容 http://php.net/array_udiff
答案 1 :(得分:0)
foreach
,array_unique
以及array_udiff
可能会对您有所帮助。
PHP手册:
对于一个简单的数组:
$result = array_unique($array);
在您的情况下,PHP手册中有一个功能:
<?php
function specified_array_unique($array, $value)
{
$count = 0;
foreach($array as $array_key => $array_value)
{
if ( ($count > 0) && ($array_value == $value) )
{
unset($array[$array_key]);
}
if ($array_value == $value) $count++;
}
return array_filter($array);
}
?>
有一篇文章与你所提出的相似; Stack Overflow - array_udiff