I need to check if Team1 exists in the XML feed. If Team1 appears twice in the XML feed, I need to output only the first instance. So far I can only output both instances. How do I accomplish this?
$str = <<<'XML'
<DATAS>
<DATA>
<VISITOR>Team6</VISITOR>
<HOME>Team7</HOME>
</DATA>
<DATA>
<VISITOR>Team1</VISITOR>
<HOME>Team2</HOME>
</DATA>
<DATA>
<VISITOR>Team3</VISITOR>
<HOME>Team1</HOME>
</DATA>
<DATA>
<VISITOR>Team4</VISITOR>
<HOME>Team5</HOME>
</DATA>
</DATAS>
XML;
$data = new SimpleXMLElement($str);
$found = false;
foreach ($data->DATA as $item) {
$teamh = $item->HOME;
$teamv = $item->VISITOR;
if ($teamh == 'Team1' || $teamv == 'Team1') {
$found = true;
echo 'Home Team: ' . $data->DATA->HOME . "
";
echo 'Away Team: ' . $data->DATA->VISITOR . "
";
}
}