我有一个包含节目和季节的 xml 文件。
我想做的是读出一个节目的季节。但问题是每个季节都在同一个节目下多次出现。
我只希望每个季节编号打印一次,例如:
Season 1
Season 2
但我现在得到的是:
Season 1
Season 2
Season 2
Season 1
Season 1
我的 xml 看起来像
<?xml version="1.0"?>
<episodeview>
<episodeview>
<idShow>1</idShow>
<idSeason>1</idSeason>
</episodeview>
<episodeview>
<idShow>1</idShow>
<idSeason>2</idSeason>
</episodeview>
<episodeview>
<idShow>1</idShow>
<idSeason>2</idSeason>
</episodeview>
<episodeview>
<idShow>1</idShow>
<idSeason>1</idSeason>
</episodeview>
<episodeview>
<idShow>1</idShow>
<idSeason>1</idSeason>
</episodeview>
</episodeview>
还有我的 php 文件:
<?php
$idShow = "1";
$source = "show.xml";
$xmlstr = file_get_contents($source);
$xmlcont = new SimpleXMLElement($xmlstr);
foreach($xmlcont as $url) {
if ($url->idShow == $idShow) {
$test = $url->idSeason;
echo "Season ";
echo $test;
echo "<br>";
}
}
?>