我有两个多维数组,我希望在这两个数组之间找到diffrnece,但是如何基于此键subscription_plan_id
获得diffrnece。
我使用了这个:$result = array_diff_assoc($arr1, $arr2);
但是收到了这个错误:
Notice: Array to string conversion in /var/www/sitename/application/models/xxx_model.php on line 122
Notice: Array to string conversion in /var/www/sitename/application/models/xxx_model.php on line 122
Notice: Array to string conversion in /var/www/sitename/application/models/xxx_model.php on line 122
Notice: Array to string conversion in /var/www/sitename/application/models/xxx_model.php on line 122
数组结果:
Array
(
[0] => Array
(
[subscription_plan_id] => 13
[plan_month] => 1
[start_date] => 2015-03-13
[end_date] => 2015-04-12
[s_start_date] => 2015-02-12 09:29:33
[s_subscription_id] => 70
)
[1] => Array
(
[subscription_plan_id] => 2
[plan_month] => 1
[start_date] => 2015-03-13
[end_date] => 2015-04-12
[s_start_date] => 2015-02-12 09:26:50
[s_subscription_id] => 69
)
)
Array
(
[0] => Array
(
[subscription_plan_id] => 2
)
[1] => Array
(
[subscription_plan_id] => 13
)
[2] => Array
(
[subscription_plan_id] => 36
)
[3] => Array
(
[subscription_plan_id] => 39
)
)
我想要这个结果:
Array
(
[0] => Array
(
[subscription_plan_id] => 36
)
[1] => Array
(
[subscription_plan_id] => 39
)
)
答案 0 :(得分:-1)
我尝试使用array_diff_key,并且使用了您的示例代码。
试试这段代码:
$arr1 = array
(
array('subscription_plan_id' => '13', 'plan_month' => '1', 'start_date' => '2015-03-13', 'end_date' => '2015-04-12', 's_start_date' => '2015-02-12 09:29:33', 's_subscription_id' => '70'),
array('subscription_plan_id' => '2', 'plan_month' => '1', 'start_date' => '2015-03-13', 'end_date' => '2015-04-12', 's_start_date' => '2015-02-12 09:26:50', 's_subscription_id' => '69')
);
$arr2 = array
(
array('subscription_plan_id' => '2'),
array('subscription_plan_id' => '13'),
array('subscription_plan_id' => '36'),
array('subscription_plan_id' => '39')
);
$diff = array_diff_key($arr2, $arr1);
echo "<pre>";
print_r($diff);
echo "</pre>";