我將兩個數組合並在一起,它們都包含一個字符串(url)和int(分數)。以下是外表的一個樣本。每當一個字符串被複制時,我需要刪除該字符串及其相應的int。例如,第4行(www.thebeatles.com/ - 30)應該被刪除。第5行和第6行也應該刪除,因爲它們看起來已經有了不同的分數。二維數組中的尷尬重複php
http://www.thebeatles.com/ - 55
http://en.wikipedia.org/wiki/The_Beatles - 49
http://www.beatlesstory.com/ - 45
http://www.thebeatles.com/ - 30
http://en.wikipedia.org/wiki/The_Beatles - 28
http://www.beatlesstory.com/ - 26
http://www.beatlesagain.com/ - 24
http://www.thebeatlesrockband.com/ - 23
http://www.last.fm/music/The+Beatles - 22
http://itunes.apple.com/us/artist/the-beatles/id136975 - 20
http://www.youtube.com/watch?v=U6tV11acSRk - 18
http://blekko.com/ws/http://www.thebeatles.com/+/seo - 17
http://www.adriandenning.co.uk/beatles.html - 16
http://www.npr.org/artists/15229570/the-beatles - 15
http://mp3.com/artist/The%2BBeatles - 14
http://www.beatles.com/ - 13
http://www.youtube.com/watch?v=TU7JjJJZi1Q - 12
http://www.guardian.co.uk/music/thebeatles - 11
http://www.cirquedusoleil.com/en/shows/love/default.aspx - 9
http://www.recordingthebeatles.com/ - 7
http://www.beatlesbible.com/ - 5
我是PHP的新手,我盡力讓array_unique()工作失敗。真的很感謝一些幫助傢伙!
'$結果=陣列(); foreach($ array as $ val){if(!isset($ result [$ val ['url']])){$ result [$ val ['url']] = $ val; }} print_r($ result);' – DaveRandom
感謝戴夫,我試過你的代碼我認爲它會工作,但我在foreach()中得到了一個未定義的變量錯誤。我應該改變什麼? – shanahobo86
嗯,你需要將'$ array'更改爲你的數組變量的名稱,並且我假設你有一個關聯數組的數組,其中有一個名爲'url'的鍵)。如果你在你的實際數組中顯示一個'print_r()',我可以給你一個有保證的工作解決方案 - 但我不應該真的只是給你一個盤子上的答案,我們喜歡它,如果人們把一個* *努力在自己...... ;-)。我使用URL作爲結果數組中的關鍵字,以便輕鬆地進行重複檢測,您可能希望通過'array_values()'傳遞'$ result'使其重新索引。 – DaveRandom