如何比较两个数组并删除从一个匹配的元素为下一个循环? [英] How to compare two arrays and remove matching elements from one for the next loop?

查看:118
本文介绍了如何比较两个数组并删除从一个匹配的元素为下一个循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

否则怎么可能你比较两个数组($ A $和B),并减少匹配元素出第一至preP超过数组$ A下一个循环?

How else might you compare two arrays ($A and $B )and reduce matching elements out of the first to prep for the next loop over the array $A?

$A = array(1,2,3,4,5,6,7,8);
$B = array(1,2,3,4);

$C = array_intersect($A,$B);  //equals (1,2,3,4)
$A = array_diff($A,$B);       //equals (5,6,7,8)

这是最简单的方法还是有使用,我没有想到的另一个函数的方法吗?我的目标是有,我可以遍历,拉出的相关内容组(我在别处定义的那些关系),直到​​数组返回false数组。

Is this the simplest way or is there a way to use another function that I haven't thought of? My goal is to have an array that I can loop over, pulling out groups of related content (I have defined those relationships elsewhere) until the array returns false.

推荐答案

您已经得到它。只要使用和array_diff或array_intersect。没有什么比这更容易。

You've got it. Just use array_diff or array_intersect. Doesn't get much easier than that.

这篇关于如何比较两个数组并删除从一个匹配的元素为下一个循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆