Invalid argument supplied for foreach()

后端 未结 19 1335
花落未央
花落未央 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:40

    Use is_array function, when you will pass array to foreach loop.

    if (is_array($your_variable)) {
      foreach ($your_variable as $item) {
       //your code
    }
    }
    

提交回复
热议问题