php while 循环,通过数组进行条件检查
假设我有两个数组:
$a = array(1,2,3,4);
$b = array(3,4,5,6);
现在我必须在所有 $a
元素完全等于数组 $b
的情况下执行某些操作
I've two arrays suppose:
$a = array(1,2,3,4);
$b = array(3,4,5,6);
Now I've to do something while all $a
element is exactly equals to array $b
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
array_diff()
array_diff()
您尝试过 array_diff() 吗?
have you tried
array_diff()
?在我看来,你可以做一些事情。
一个非常简单和基本的方法是循环并在其中有一些逻辑来检查 $a[$val] == $b[$val] 以及是否执行某些操作,否则不执行。
就像上面好心人所说的那样,PHP 中有一个名为 array_diff() 的函数,它可以计算数组中的差异。下面的示例取自 PHP.net 站点。
所以这完全取决于你想做什么。如果您想让您的陈述更清楚,请这样做,我将尝试相应地重新回答。
谢谢
There are a few things you could do here in my mind.
A VERY simple and basic way would be to loop through and have some logic in there to check if $a[$val] == $b[$val] and if it is do something, otherwise not.
Like the good people above said, there is a function in PHP called array_diff() which computes the difference in arrays. The below example is taken from the PHP.net site.
So it depends on exactly what you want to do. If you wish to make your statement more clear then please do so and I will try to re-answer accordingly.
Thanks