PHP:比较数组的值
$a1 = array('A', 'A', 'A', 'A', 'B', 'C');
$a2 = array('A', 'A', 'A', 'A', 'B', 'C');
我想将 $a1
中的第一个 'A'
与 $a2
中的最后一个 'A'
进行匹配。以及 $a1
中的第二个 'A'
以及 $a1
中的 倒数第二个 'A'
>$a2。
$a1
和 $a2
,如下所示:
0 => 'A' with 3 => 'A'
1 => 'A' with 2 => 'A'
2 => 'A' with 1 => 'A'
3 => 'A' with 0 => 'A'
我需要一个 if 语句来确定 中是否存在另一个
将其与其在 'A'
实例$a1$a2
中的相应值进行匹配
$a1 = array('A', 'A', 'A', 'A', 'B', 'C');
$a2 = array('A', 'A', 'A', 'A', 'B', 'C');
I want to match the first 'A'
in $a1
with the last 'A'
in $a2
. And the second 'A'
in $a1
with the second-from-last 'A'
in $a2
.
$a1
with $a2
, like so:
0 => 'A' with 3 => 'A'
1 => 'A' with 2 => 'A'
2 => 'A' with 1 => 'A'
3 => 'A' with 0 => 'A'
I need an if statement to determine if there is another instance of 'A'
in $a1
to match it with its respective value in $a2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只想按照您描述的相反顺序匹配“A”,您可以尝试以下操作:
In case you just want to match 'A' in the reverse order that you described, you can try this:
我的建议:
?>
输出:
My suggestion:
?>
Outputs:
这正是你所解释的。它不太完整,但它比较了您所解释的两个数组并且更紧凑。
This do exactly what you explain. Its less complete but It compares both arrays as you explain and is more compact.