如何使两个 foreach 循环变干?

How to make two foreach loops DRY?

我想不出一种方法将其缩减为一个循环。每个循环中的处理是相同的。我会展示我尝试过的东西,但我什至不知道该尝试什么。

<?

if($xml->entry){
  foreach ($xml->entry as $item) {
    ...
  }
else{
  foreach($rss->channel->item as $item) {
    ...
  }
}
foreach (($xml->entry ? $xml->entry : $rss->channel->item) as $item) {
    ...
}
$items = $xml->entry ? $xml->entry : $rss->channel->item;

foreach( $items as $item ) {
  ...
}