Invalid argument supplied for foreach()

后端 未结 19 1365
花落未央
花落未央 2020-11-21 06:32

It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data.

$values = get_val         


        
19条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 06:47

    Exceptional case for this notice occurs if you set array to null inside foreach loop

    if (is_array($values))
    {
        foreach ($values as $value)
        {
            $values = null;//WARNING!!!
        }
    }
    

提交回复
热议问题