Re: Multidimensional array: deleting a nested array because first element duplicates first element in another nested array

From: Date: Sat, 26 Apr 2003 15:15:54 +0000
Subject: Re: Multidimensional array: deleting a nested array because first element duplicates first element in another nested array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145360@lists.php.net to get a copy of this message
I am going to try this really quickly, so follow along closely... <? $a = array( array( "title" => "Colorado Avalanche playoff history", "link" => "http://c.moreover.com/click/here.pl?r69021036", "description" => "FOXSports.com Apr 23 2003 9:28AM ET", ), array( "title" => "UF vice president finalist for Colorado State presidency", "link" => "http://c.moreover.com/click/here.pl?r69014747", "description" => "Stuart News Apr 23 2003 8:51AM ET", ), array( "title" => "UF vice president finalist for Colorado State presidency", "link" => "http://c.moreover.com/click/here.pl?r69014428", "description" => "Jupiter Courier Apr 23 2003 8:50AM ET", ) ); for($i=0; $i<count($a); $i++) { $title1 = $a[$i]['title']; if(isset($a[$i+1])) if( $title1 == $a[$i+1]['title'] ) unset($a[$i]); } echo "<pre>"; print_r($a); ?> Tested and it gave me the results that you are looking for. Jim Lucas ----- Original Message ----- From: "Mike Connelly" <news.php.net@shepherdstown.com> To: <php-general@lists.php.net> Sent: Friday, April 25, 2003 8:47 AM Subject: [PHP] Multidimensional array: deleting a nested array because first element duplicates first element in another nested array > 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) "Ú™^M¨Á’iÖ_ > ¼çJhttp://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! > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#145360) next »