比较相同的数组值 [英] compare same array values

查看:85
本文介绍了比较相同的数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是PHP在同一阵列中比较elments的最佳方式,因此,如果有两个elemets与数组A相同的价值观,我可以通过一个函数作为参数做财产以后?

What is the best way to compare elments in the same array in PHP, so that if there are two elemets with the same values in array A, I can pass a function as argument to do somthing ?

推荐答案

您可以使用的 array_count_values​​ 和的 in_array 功能:

You can use array_count_values and in_array functions as:

if(in_array(2,array_count_values($array)) {
  // do something
}

这篇关于比较相同的数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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