Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Unikalne wartości, z tablicy dwuwymiarowej
-merrit-
post
Post #1





Goście







Jak uzyskać tablicę bez powtarzających się wartości [link] w następującej tablicy?

Kod
Array
(
    [0] => Array
        (
            [title] => Some feed item
            [link] => http://www.example.com/article34
            [description] => This article is really cool!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 13:28:11 GMT
        )

    [1] => Array
        (
            [title] => Some feed item2
            [link] => http://www.example.com/article34
            [description] => This article is really cool too!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 12:57:56 GMT
        )

    [2] => Array
        (
            [title] => Some feed item3
            [link] => http://www.example.com/article4523
            [description] => This article is the best!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 12:39:42 GMT
        )

)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Bawisz się z array_unique badz...
Kod
function deleteDuplicate($tab)
{
$unique=array();
$ile=count($tab); // KONIECZNE!
for($i=0; $i<$ile; $i++)
{
    if(!in_array($tab[$i]['link'], $unique) $unique[]=$tab[$i]['link']
    else unset($tab[$i]);
}

// jeżeli chcesz jeszce zresetować klucze na koniec to daj $tab=array_merge($tab);
return $tab;
}

print_r(deleteDuplicate($tab));


Tablica wynikowa to:
Kod
Array
(
    [0] => Array
        (
            [title] => Some feed item
            [link] => http://www.example.com/article34
            [description] => This article is really cool!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 13:28:11 GMT
        )

    [2] => Array
        (
            [title] => Some feed item3
            [link] => http://www.example.com/article4523
            [description] => This article is the best!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 12:39:42 GMT
        )

)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 01:28