如何将文件数据array()与普通数组进行比较 [英] How to compare file data array() with normal array

查看:102
本文介绍了如何将文件数据array()与普通数组进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用fgets()将文件字符串拆分为数组,并使用explode()

另一方面,我从用户那里获取字符串,然后将其拆分为数组

当我通过使用array_intersect()比较2个数组时,我有2个数组

(即使使用2个foreach(作为最后一次尝试))...它甚至返回null数组(Array())如果他们有共同的元素

为什么?

是否需要将文件数据与普通数组进行比较的特殊设置/参数/语法?

Am spliting file string into array by using fgets(),and explode()
On other hand am taking string from user,and again spliting it into array
now I have 2 array
when I compare 2 arrays by using array_intersect()(even by using 2 foreach(as a last try))...it is returning null array(Array()) even if they have common elements
WHY?
is any special settings/parameter/syntax require to compare file data with normal array?

推荐答案

让我们看看两个数组的一部分
Let us see a portion of both arrays


你需要找到2个数组中的公共元素吗?


u can循环通过较大的一个..使用count()来查找哪一个更大


然后使用in_array()函数和if循环中的条件来查找是否每个元素都在大数组已存在于其他数组中..


里面如果cindition你可以在第三个数组中添加这个常见元素,如果你想这样
do u need to find common elements in 2 arrays ?

u can loop through the bigger one.. "use count() to find which one is bigger"

then use in_array() function and if condition inside the loop to find if each element in big array is already exist in other array..

inside if cindition u can add this common elements in third array if u want like this

展开 | 选择 | Wrap | 行号


@Shenno:...你刚刚重建了 array_intersect()
@Shenno: ... You just rebuilt array_intersect().


这篇关于如何将文件数据array()与普通数组进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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