$sourceValue) { if ($sourceValue['tag'] == 'NAME') { $xmlData[$i]['name'] = $sourceValue['value']; } if ($sourceValue['tag'] == 'CAPTION') { $xmlData[$i]['caption'] = (!empty($sourceValue['value']) ? $sourceValue['value'] : ''); $i++; } } foreach ($xmlData as $xmlKey => $xmlValue) { if ($xmlValue['name'] == $imageName) { $imageCaption = $xmlValue['caption']; break; } } ?>