比较 PHP 中的多维数组
我试图与多维数组进行比较,但我不能只使用 array_diff_assoc()。 我尝试比较的数组都是关联数组,并且它们都已排序,因此键的顺序相同。 大多数情况下,数组的结构是相同的。 我似乎不知道如何比较存储数组的元素,我可以很好地比较保存一个值的元素有人知道我能做什么吗?
I am trying to compare to multidimensional arrays, but I can't just use array_diff_assoc(). The arrays I am trying to compare are both associative arrays, and they are both sorted so the keys are in the same order. For the most part the arrays are identical in structure. I can't seem to figure out how to compare the elements that store arrays, I can compare the elements that hold one value just fine does anyone know what I can do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只是想看看它们是否不同(而不是具体有什么不同),您可以尝试类似的操作:
这会给您一个关于两个数组相等的肯定或否定的结果。
If your trying to just see if they are different (and not what specifically is different) you could try something like:
That would give you a yea or neah on the equality of the two arrays.
目前尚不清楚您是否想要查看它们是否相等,或者实际上想要输出差异是什么。
如果是前者,那么您可以使用递归函数以正确的方式完成它:
或者使用像这样的完整黑客:
It's not clear whether you want to see if they're equal, or actually want an output of what the differences are.
If it's the former then you could do it the proper way, with a recursive function:
Or use a complete hack like this: