我一直得到in_array()期望参数2是数组,我该怎么解决?

时间:2017-08-14 10:15:23

标签: php parameters

  

警告:in_array()期望参数2为数组,在第229行文件位置隐藏安全中给出

第223-235行

\#(.*?)

我已添加内插数字,以帮助了解线条的位置。 任何帮助将不胜感激

2 个答案:

答案 0 :(得分:3)

您需要确保$mgroup_others_array实际上是一个数组。

您可以将if更改为:

if (is_array($mgroup_others_array) && in_array($id, $mgroup_others_array)) {

这会阻止你warning。您无法对不属于该变量的变量执行in_array()调用。

答案 1 :(得分:0)

你也可以这样做:

if (count($dmos_forum_ids) > 0) {

    $new_mgroup_others_array = array();  
    if(!is_array($mgroup_others_array))
        $mgroup_others_array = array();
    // Loop through the new mgroups and make sure they are added to the existing
    foreach ($dmos_forum_ids as $id) 
    {
        if (in_array($id, $mgroup_others_array)) 
        {
            array_push($new_mgroup_others_array, $id);

        }       
    }       
}