Invalid argument supplied for foreach()

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

    i would do the same thing as Andy but i'ld use the 'empty' function.

    like so:

    if(empty($yourArray))
    {echo"<p>There's nothing in the array.....</p>";}
    else
    {
    foreach ($yourArray as $current_array_item)
      {
        //do something with the current array item here
      } 
    }
    
    0 讨论(0)
提交回复
热议问题