I am using this and when I am echoing there, it's coming from an array and the results are not even. For example if A goes with 1, I am getting B with 1 and c with 2 etc.. The results are uneven which I think is because of the case. Is there anyway that I can even them out on the return? foreach ($values as $key=>$val) { switch ($val['tag']) { case 'DetailPageURL': $DetailPageURL = $val['value']; echo '<img border="0" src="'.$MediumImage.'" height="100">'; break; case 'ItemAttributes': $inItemAttributes = ($val['type'] == 'open'); echo '<h1><a href='.$DetailPageURL.'>'.$itemAttributes['Title'].'</a></h1><br>'.$itemAttributes['FormattedPrice'].'<hr>'; break; case 'MediumImage': $inMediumImage = ($val['type'] == 'open'); break; case 'EditorialReview': $inEditorialReview = ($val['type'] == 'open'); break; case 'Content': if ($inEditorialReview) $EditorialReview = $val['value']; break; case 'URL': if ($inMediumImage) $MediumImage = $val['value']; break; default: if ($inItemAttributes) { $itemAttributes[$val['tag']] = $val['value']; } } } //$Title = $itemAttributes['Title']; //echo "<h1><a href=\"$DetailPageURL\">$Title</a></h1>"; //echo "<img src=\"$MediumImage\" align=\"right\">"; //echo $EditorialReview; } PHP:
Can you clarify with an example what you mean by this? From a quick glance: You might want to clear some or all of the contents of $itemAtributes before the switch block. Each iteration of foreach is re-using $itemAttributes that was changed in previous iterations. If this isn't intentional, start there.
Actually that is an array. $inItemAttributes = false; $inMediumImage = false; $inEditorialReview = false; $itemAttributes = array(); foreach ($values as $key=>$val) { switch ($val['tag']) { case 'DetailPageURL': $DetailPageURL = $val['value']; echo '<img border="0" src="'.$MediumImage.'" height="100">'; break; case 'ItemAttributes': $inItemAttributes = ($val['type'] == 'open'); echo '<h1><a href='.$DetailPageURL.'>'.$itemAttributes['Title'].'</a></h1><br>'.$itemAttributes['FormattedPrice'].'<hr>'; break; case 'MediumImage': $inMediumImage = ($val['type'] == 'open'); break; case 'EditorialReview': $inEditorialReview = ($val['type'] == 'open'); break; case 'Content': if ($inEditorialReview) $EditorialReview = $val['value']; break; case 'URL': if ($inMediumImage) $MediumImage = $val['value']; break; default: if ($inItemAttributes) { $itemAttributes[$val['tag']] = $val['value']; } } } PHP:
Yes, from the usage in your sample code, it was clear that $itemAttributes is an array there. However, without further details, the recommendation is the same: Please carefully read and provide additional detail if your problem persists. Good luck!