2014-03-17 08:12
浏览 203

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

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

图片转代码服务由CSDN问答提供 功能建议

我有五个数组并搜索哪个用户可以随机搜索。 因此,对于这五个有时可能有两个数组,三个数组或五个数组等等的值。

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

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

实际上我需要检查并使其动态化,如果有 $ g_arr,$ c_arr 的值,那么上面的操作将适用于这两个..喜欢

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

我不明白如何检查 ? 任何帮助将不胜感激..谢谢

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongping4273 2014-03-17 08:28
    $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);
    解决 无用
    打赏 举报

相关推荐 更多相似问题