Remove duplicate entries in an array (iTunes API)

Hello!

I have a small issue where I’m trying to remove duplicate entries from an array, the array its-self contains another set of arrays, example below…

[php]Array ( [0] => Array ( [wrapperType] => track [kind] => song [artistId] => 156857565 [collectionId] => 283175944 [trackId] => 283175947 [artistName] => Basshunter [collectionName] => All I Ever Wanted (Radio Edit) - Single [trackName] => All I Ever Wanted [collectionCensoredName] => All I Ever Wanted (Radio Edit) - Single [trackCensoredName] => All I Ever Wanted (Radio Edit) [artistViewUrl] => http://itunes.apple.com/gb/artist/basshunter/id156857565?uo=4 [collectionViewUrl] => http://itunes.apple.com/gb/album/all-i-ever-wanted-radio-edit/id283175944?i=283175947&uo=4 [trackViewUrl] => http://itunes.apple.com/gb/album/all-i-ever-wanted-radio-edit/id283175944?i=283175947&uo=4 [previewUrl] => http://a1.mzstatic.com/us/r1000/040/Music/34/9b/07/mzm.swcerwft.aac.p.m4a [artworkUrl30] => http://a4.mzstatic.com/us/r1000/051/Music/a4/eb/c1/mzi.yprcejle.30x30-50.jpg [artworkUrl60] => http://a3.mzstatic.com/us/r1000/051/Music/a4/eb/c1/mzi.yprcejle.60x60-50.jpg [artworkUrl100] => http://a1.mzstatic.com/us/r1000/051/Music/a4/eb/c1/mzi.yprcejle.100x100-75.jpg [collectionPrice] => 0.79 [trackPrice] => 0.79 [releaseDate] => 2008-06-29T07:00:00Z [collectionExplicitness] => notExplicit [trackExplicitness] => notExplicit [discCount] => 1 [discNumber] => 1 [trackCount] => 1 [trackNumber] => 1 [trackTimeMillis] => 184067 [country] => GBR [currency] => GBP [primaryGenreName] => Dance ) [1] => Array ( [wrapperType] => track [kind] => song [artistId] => 156857565 [collectionId] => 284574742 [trackId] => 284574763 [artistName] => Basshunter [collectionName] => Now You’re Gone [trackName] => Angel In the Night [collectionCensoredName] => Now You’re Gone [trackCensoredName] => Angel In the Night [artistViewUrl] => http://itunes.apple.com/gb/artist/basshunter/id156857565?uo=4 [collectionViewUrl] => http://itunes.apple.com/gb/album/angel-in-the-night/id284574742?i=284574763&uo=4 [trackViewUrl] => http://itunes.apple.com/gb/album/angel-in-the-night/id284574742?i=284574763&uo=4 [previewUrl] => http://a3.mzstatic.com/us/r1000/027/Music/d0/df/d9/mzm.bxrzjelt.aac.p.m4a [artworkUrl30] => http://a5.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.30x30-50.jpg [artworkUrl60] => http://a4.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.60x60-50.jpg [artworkUrl100] => http://a4.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.100x100-75.jpg [collectionPrice] => 4.49 [trackPrice] => 0.79 [releaseDate] => 2008-07-14T07:00:00Z [collectionExplicitness] => notExplicit [trackExplicitness] => notExplicit [discCount] => 1 [discNumber] => 1 [trackCount] => 18 [trackNumber] => 5 [trackTimeMillis] => 201293 [country] => GBR [currency] => GBP [primaryGenreName] => Dance ) [2] => Array ( [wrapperType] => track [kind] => song [artistId] => 156857565 [collectionId] => 284574742 [trackId] => 284574756 [artistName] => Basshunter [collectionName] => Now You’re Gone [trackName] => I Miss You [collectionCensoredName] => Now You’re Gone [trackCensoredName] => I Miss You [artistViewUrl] => http://itunes.apple.com/gb/artist/basshunter/id156857565?uo=4 [collectionViewUrl] => http://itunes.apple.com/gb/album/i-miss-you/id284574742?i=284574756&uo=4 [trackViewUrl] => http://itunes.apple.com/gb/album/i-miss-you/id284574742?i=284574756&uo=4 [previewUrl] => http://a5.mzstatic.com/us/r1000/020/Music/1c/f5/01/mzm.lsqbxykj.aac.p.m4a [artworkUrl30] => http://a5.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.30x30-50.jpg [artworkUrl60] => http://a4.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.60x60-50.jpg [artworkUrl100] => http://a4.mzstatic.com/us/r1000/039/Music/25/02/93/mzi.gfzgtifm.100x100-75.jpg [collectionPrice] => 4.49 [trackPrice] => 0.79 [releaseDate] => 2008-07-14T07:00:00Z [collectionExplicitness] => notExplicit [trackExplicitness] => notExplicit [discCount] => 1 [discNumber] => 1 [trackCount] => 18 [trackNumber] => 4 [trackTimeMillis] => 225933 [country] => GBR [currency] => GBP [primaryGenreName] => Dance ) [3] => Array ( [wrapperType] => track [kind] => song [artistId] => 156857565 [collectionId] => 270417709 [trackId] => 270417710 [artistName] => Basshunter [collectionName] => Now You’re Gone (Radio Edit) - Single [trackName] => Now You’re Gone [collectionCensoredName] => Now You’re Gone (Radio Edit) - Single [trackCensoredName] => Now You’re Gone [artistViewUrl] => http://itunes.apple.com/gb/artist/basshunter/id156857565?uo=4 [collectionViewUrl] => http://itunes.apple.com/gb/album/now-youre-gone/id270417709?i=270417710&uo=4 [trackViewUrl] => http://itunes.apple.com/gb/album/now-youre-gone/id270417709?i=270417710&uo=4 [previewUrl] => http://a2.mzstatic.com/us/r1000/018/Music/c6/21/b7/mzm.gqtdsjbp.aac.p.m4a [artworkUrl30] => http://a3.mzstatic.com/us/r1000/027/Music/14/5d/0f/mzi.agvvqndb.30x30-50.jpg [artworkUrl60] => http://a2.mzstatic.com/us/r1000/027/Music/14/5d/0f/mzi.agvvqndb.60x60-50.jpg [artworkUrl100] => http://a5.mzstatic.com/us/r1000/027/Music/14/5d/0f/mzi.agvvqndb.100x100-75.jpg [collectionPrice] => 0.79 [trackPrice] => 0.79 [releaseDate] => 2007-12-31T08:00:00Z [collectionExplicitness] => notExplicit [trackExplicitness] => notExplicit [discCount] => 1 [discNumber] => 1 [trackCount] => 1 [trackNumber] => 1 [trackTimeMillis] => 154668 [country] => GBR [currency] => GBP [primaryGenreName] => Dance ) ) [/php]

The thing is the trackName is duplicated here, i want to only have a clean array with no duplicates to show songs for the current artist.

[php]$getart = $result[‘musicartist’];
$getart = str_replace(" ", “%20”, $getart);
$cas = curl_init(“http://itunes.apple.com/search?parameterkeyvalue&term=".$getart."&entity=song&attribute=artistTerm&media=music&version=2&limit=100&country=GB”);
curl_setopt($cas, CURLOPT_RETURNTRANSFER, 1);
$jsonitunes = curl_exec($cas);
curl_close($cas);

	$arr = json_decode($jsonitunes,true);
	
	$items = array();
	foreach($arr['results'] as $item) {
		$items[] = $item;
	};

	function cmp($a, $b)
	{
		return strcmp($a["trackName"], $b["trackName"]);
	}

	usort($items, "cmp");[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service