php array_intersect making issues and i'm not able to check the empty array

萝らか妹 提交于 2019-12-25 06:54:02

问题


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);

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


回答1:


$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);


来源:https://stackoverflow.com/questions/22449442/php-array-intersect-making-issues-and-im-not-able-to-check-the-empty-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!