我有一个可以打印新闻稿的XML文件。我想回想一下新闻稿发布的所有年份,就像一个档案馆。仅限唯一值。下面的代码打印出了所有年份。比如"2017,2017,2017,2016,2016,2015,2015,2014“,而不是"2017,2016,2015,2014,2013”。
<?php
$file = "file.xml";
$xml = simplexml_load_file($file);
foreach ($xml->Release as $release) {
$date = $release['PublishDateUtc']; /* $date is now in format yyyy-mm-ddT06:30:00 */
$year = substr($date, 0, 4);
echo $year;
}
?>https://stackoverflow.com/questions/44410902
复制相似问题