mercredi 20 mai 2015

Warning about part of if-statement that evaluates to false

The following code causes a Invalid argument supplied for foreach() warning, even though the part that causes it is blocked by the surrounding if-statement. Why is it even reaching that point and what can I do about it?

<?php $terms = array(); // can be of different length but is always an array
if( count( $terms ) > 0 ) :
  foreach( $terms as $term ) : // Invalid argument supplied for foreach()
    foreach( $team_list as $post ) :    
      // stuff
    endforeach;
  endforeach; 
else:
  foreach( $team_list as $post ) :  
    // stuff
  endforeach;
endif; ?>

Aucun commentaire:

Enregistrer un commentaire