I'm workking on a shortcode for wordpress and did a loop and stored a few variables in an array some of my posts won't have anything in the array and i'm getting an error for the ones that do.
My two arrays are
$class_cards[]=array('card_count'=>$card_count,'has_term'=>$has_term,'card_img_class'=>$card_img_class,'card'=>$card,'card_title'=>$card_title,'card_mana'=>$card_mana,'card_slug'=>$card_slug);
$neutral_cards[]=array('card_count'=>$card_count,'has_term'=>$has_term,'card_img_class'=>$card_img_class,'card'=>$card,'card_title'=>$card_title,'card_mana'=>$card_mana,'card_slug'=>$card_slug);
I then output them with the code below, the issue I'm having is with most posts we have values stored in both arrays and output them and everything works great, but if we have values stored in just the $class_cards array and nothing in the neutral cards array I get the error
Warning: Invalid argument supplied for foreach() in /home/hsp/public_html/wp-content/themes/hsp/content/deck-info.php on line 264
The output looks like this, so what I'm asking is how can I check to make sure there is something in those arrays to fix this error
// Output Class Cards
$output .= '<div class="class-cards">';
$output .= 'Class Cards ('. $total_class_cards .')';
$output .= '<span class="sc-deck-mana-cost"><img src="http://hearthstoneplayers.com/img/icons/dust.png" />'.$crafting_cost.'</span>';
$i=0;
while($i<=20)
{
foreach($class_cards as $row=>$value)
{
if($value['card_mana']==$i)
{
$output .= '
<div class="card">
'. $value['card_count'] .'
<div class="card-overlay"></div>
<div '. $value['card_img_class'] .' ><img src="http://hearthstoneplayers.com/img/cards/'. $value['card'] .'.png"></div>
<div class="decklist-tooltip"><img src="http://hearthstoneplayers.com/img/cards/'. $value['card'] .'.png"></div>
<span class="card-title">'. $value['card_title'] .'</span>
<span class="mana-icon"><img src="http://hearthstoneplayers.com/img/icons/mana.png" /></span>
<span class="mana-cost">'. $value['card_mana'] .' </span>
<a class="dl-card-link" href="http://hearthstoneplayers.com/cards/'. $value['card'] .'/"></a>
</div>
';
}
}
++$i;
}
$output .= '</div>'; // Close Div class-cards
// Output Neutral Cards
$output .= '<div class="neutral-cards">';
$i=0;
while($i<=20)
{
foreach($neutral_cards as $row1=>$value1)
{
if($value1['card_mana']==$i)
{
$output .= '
<div class="card">
'. $value1['card_count'] .'
<div class="card-overlay"></div>
<div '. $value1['card_img_class'] .' ><img src="http://hearthstoneplayers.com/img/cards/'. $value1['card'] .'.png"></div>
<div class="decklist-tooltip"><img src="http://hearthstoneplayers.com/img/cards/'. $value1['card'] .'.png"></div>
<span class="card-title">'. $value1['card_title'] .'</span>
<span class="mana-icon"><img src="http://hearthstoneplayers.com/img/icons/mana.png" /></span>
<span class="mana-cost">'. $value1['card_mana'] .' </span>
<a class="dl-card-link" href="http://hearthstoneplayers.com/cards/'. $value1['card'] .'/"></a>
</div>
';
}
}
++$i;
}
$neutral_cardsin your code. Please post line 264 of/home/hsp/public_html/wp-content/themes/hsp/content/deck-info.phpprint_r($class_cards );beforeforeach($class_cards as $row=>$value)if it is the line 264.$class_cardsdefinitely empty or not set at all.