不同大小的相交多维数组
问题描述
我有一个如下所示的多维数组:
I have a multidimensional array that looks like this:
我需要找到一种返回相交值的方法.在这种情况下,这将是
I need to find a way to return the intersecting value(s). In this case that would be
数组的长度可能不同,所以我不能只使用array_intersect().
The length of the array could be different, so I can't just use array_intersect().
推荐答案
如果你的数组只包含整数,这会很简单,但是当它们包含另一个数组时,它会变得有点复杂.但这应该可以:
This would be simple if your arrays contained only integers, but as they contain an another array, it gets a bit more complicated. But this should do it:
用法:
结果:
此功能并不完美:如果您在一个数组中有重复的 ID,它将无法工作.这将需要更多的代码来首先使数组值唯一,但这可能适用于您的情况.
This function isn't perfect: if you have duplicate ID's in one array, it will not work. That would require a bit more code to first make the array values unique, but this will probably work in your case.
这篇关于不同大小的相交多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!