php array_intersect产生问题,我无法检查空数组 [英] php array_intersect making issues and i'm not able to check the empty array

查看:109
本文介绍了php array_intersect产生问题,我无法检查空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个数组和一个搜索,用户可以对其进行随机搜索.因此,对于这五个数组,有时可能会有两个数组,三个数组或五个数组之类的值.

I have five arrays and a search for which user can do search randomly. So for among those five sometimes there may be value for two arrays, three arrays or five arrays and whatever.

所以当我相交时,我无法检查哪个是空的,因此它总是返回一个空数组.

So When I intersect I am not be able to check which are empty so that it always returns an empty array.

$full_ids = array_intersect($g_arr, $c_arr, $k_arr, $m_arr, $p_arr);

实际上,我需要检查并使其具有动态性,例如是否有$g_arr, $c_arr的值,然后上述操作将与这两个应用..像

Actually I need to check and make this dynamic like if there are values for $g_arr, $c_arrthen the above operation will be applied with these two.. like

$full_ids = array_intersect($g_arr, $c_arr);

我不知道该如何检查?任何帮助将不胜感激..谢谢

I don't understand how to check that? Any help w'd be appreciated..thanks

推荐答案

$tempArray = [];
if (count($g_arr) >0) $tempArray[] = $g_arr;
if (count($c_arr) >0) $tempArray[] = $c_arr;
if (count($k_arr) >0) $tempArray[] = $k_arr;
if (count($m_arr) >0) $tempArray[] = $m_arr;
if (count($p_arr) >0) $tempArray[] = $p_arr;

$intersect = call_user_func_array('array_intersect', $tempArray);

这篇关于php array_intersect产生问题,我无法检查空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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