从多维数组中提取值
我有两个像这样结构的数组
$array1 = Array
(
[0] => Array
(
['story_id'] => 47789
)
[1] => Array
(
['story_id'] => 47779
)
[2] => Array
(
['story_id'] => 47776
)
[3] => Array
(
['story_id'] => 47773
)
[4] => Array
(
['story_id'] => 47763
)
)
$array2 = Array
(
[0] => Array
(
['story_id'] => 47789
)
[1] => Array
(
['story_id'] => 47777
)
[2] => Array
(
['story_id'] => 47776
)
[3] => Array
(
['story_id'] => 47773
)
[4] => Array
(
['story_id'] => 47763
)
)
,我想得到 array1 和 array2 的区别,所以我尝试使用
$results = array_diff($array1, $array2);
,但结果是空的,有没有简单的方法可以解决这个问题,或者最好让我将数组归结为如果是这样,有没有简单的方法可以做到这一点?
I have two arrays that are structured like this
$array1 = Array
(
[0] => Array
(
['story_id'] => 47789
)
[1] => Array
(
['story_id'] => 47779
)
[2] => Array
(
['story_id'] => 47776
)
[3] => Array
(
['story_id'] => 47773
)
[4] => Array
(
['story_id'] => 47763
)
)
$array2 = Array
(
[0] => Array
(
['story_id'] => 47789
)
[1] => Array
(
['story_id'] => 47777
)
[2] => Array
(
['story_id'] => 47776
)
[3] => Array
(
['story_id'] => 47773
)
[4] => Array
(
['story_id'] => 47763
)
)
and I want to get the difference of array1 from array2 so I tried using
$results = array_diff($array1, $array2);
but it turns up empty is there any easy way around this or would it be best for me to get the arrays boiled down and if so is there easy way to do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
array_diff
仅用于一维数组。对于你的 2 数组,让我们使用 php.net 中的一些代码It because that the
array_diff
is only use for 1 dimension array. For your 2 array, let use some code from php.net