你可以存儲的ID的將一個對象數組作爲一個簡單的1d數組,然後在循環其他feed時檢查另一個ID是否存在。
# Create your variables to store the ID's of the two feeds
$ids_1 = array();
$ids_2 = array();
# Populate the arrays
foreach ($feed->data as $item1) {
$ids_1[] = $item1->id;
}
foreach ($feed2->data as $item2) {
$ids_2[] = $item2->id;
}
# Loop through the first feed, and exclude the items that are the same in the second
foreach($feed->data as $item){
if (!in_array($item->id, $ids2)) {
echo $item->id;
}
}
# Loop through the second feed, and exclude the items that are the same in the first
foreach($feed2->data as $item){
if (!in_array($item->id, $ids1)) {
echo $item->id;
}
}
希望有所幫助。
注意它們提供了相同的數據,唯一的區別是我不打算在顯示中使用的一個屬性!如果你明白我的意思!! – MidnightCoder 2012-02-16 05:23:51