Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Unikalne wartości, z tablicy dwuwymiarowej
-merrit-
post 13.08.2008, 23:41:22
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 15.08.2008, 07:34:56
Post #2





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




To widze, że ty się nie "zastanawiasz" tylko odrazu walisz takie głupoty.
Nawet nie umiesz poprawić kodu.
Kod
<?php
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]);
}

$tab=array_merge($tab);
return $tab;
}


$tab=Array
(
    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'
    ),

    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'
    ),

    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'
    )

);

print_r(deleteDuplicate($tab));
?>

I sprawdź sobie "wielki myślicielu" czy to nie działa poprawnie.


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 23:14