Multidimensional array: deleting a nested array because first element duplicates first element in another nested array
| From: | Mike Connelly | Date: | Fri, 25 Apr 2003 15:47:22 +0000 |
| Subject: | Multidimensional array: deleting a nested array because first element duplicates first element in another nested array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-145279@lists.php.net to get a copy of this message | ||
I continue to Google both the Internet and Newsgroups for an answer to this question. Unfortunately, I haven't found an answer.
I have restated the question in the subject above because I think that this terminology is more accurate than my earlier posting.
"In a multidimensional array, how do I delete a nested array because the first element in that nested array is a duplicate of the first element in another nested array?"
===============================================================
I have an RSS feed (parsed using MagpieRSS RSS reader) which searches
for keyword matches across a variety of news organizations. I want to
eliminate all but one of those items within the RSS feed that have
duplicate titles (because the articles are syndicated).
Put another way, I have an array of nested arrays and I want to
eliminate certain nested arrays based on duplicated values within the
first element of the nested array.
The array_unique function doesn't work correctly with nested arrays. And
notes on the php.net site referring to nested array serialization don't
apply because other elements (such as the news organization which is
distributing the syndicated article) may be different in the nested
array (even though the article, as identified by its title, remains the
same).
For example, here is a partial cut and paste of a vardump of
($rss->items)....
=====================================================================
array(10) {
[0]=>
array(3) {
["title"]=>
string(34) "Colorado Avalanche playoff history"
["link"]=>
string(45) "http://c.moreover.com/click/here.pl?r69021036"
["description"]=>
string(35) "FOXSports.com Apr 23 2003 9:28AM ET"
}
[1]=>
array(3) {
["title"]=>
string(56) "UF vice president finalist for Colorado State presidency"
["link"]=>
string(45) "http://c.moreover.com/click/here.pl?r69014747"
["description"]=>
string(33) "Stuart News Apr 23 2003 8:51AM ET"
}
[2]=>
array(3) {
["title"]=>
string(56) "UF vice president finalist for Colorado State presidency"
["link"]=>
string(45) "http://c.moreover.com/click/here.pl?r69014428"
["description"]=>
string(37) "Jupiter Courier Apr 23 2003 8:50AM ET"
}
=====================================================================
"UF vice president finalist for Colorado State presidency" appears twice
and I want to eliminate all but the oldest instance. So, here is my
desired result:
=====================================================================
array(10) {
[0]=>
array(3) {
["title"]=>
string(34) "Colorado Avalanche playoff history"
["link"]=>
string(45) "http://c.moreover.com/click/here.pl?r69021036"
["description"]=>
string(35) "FOXSports.com Apr 23 2003 9:28AM ET"
}
[2]=>
array(3) {
["title"]=>
string(56) "UF vice president finalist for Colorado State presidency"
["link"]=>
string(45) "http://c.moreover.com/click/here.pl?r69014428"
["description"]=>
string(37) "Jupiter Courier Apr 23 2003 8:50AM ET"
}
=====================================================================
Your help would be appreciated!