Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> sortowanie tablicy trójwymiarowej
Leech
post
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 26.07.2007

Ostrzeżenie: (0%)
-----


witam,
jak posortować taką tablicę:
  1. <?php
  2. Array ( [0] => Array(
  3.  [0] => Array ( [align] => center [params] => class="productListing-heading" [text] =>    )
  4. [1] => Array ( [align] => [params] => class="productListing-heading" [text] =>  Produkt+  )
  5. [2] => Array ( [align] => right [params] => class="productListing-heading" [text] =>  Cena  )
  6. [3] => Array ( [align] => center [params] => class="productListing-heading" [text] =>    )
  7. [4] => Array ( [align] => center [params] => class="productListing-heading" [text] =>  kategoria  ) ) )
  8. ?>


wg klucza którym jest [0][4][text] ? Podalem pierwszy element tablicy, a elementów jest nieokreślona ilość

Ten post edytował Leech 2.10.2008, 13:00:19
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Cienki1980
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 590
Pomógł: 40
Dołączył: 11.01.2007
Skąd: Centrum

Ostrzeżenie: (0%)
-----


Spróbuj takiego kodu:
  1. <?php
  2. function SortMultiArrayMultiLevel($InArray,$Columns,$SortType)
  3.    {
  4.        //initialize variables
  5.        $TmpArray       = array();
  6.        $ResultArray    = array();
  7.        $Index          = 0;
  8.                $SortTrans=Array(
  9.                      " "=>"9",
  10.                      "-"=>".",
  11.                      "ś"=>"szz",
  12.                      "Ľ"=>"zzz",
  13.                      "ą"=>"azz",
  14.                      "Ś"=>"szz",
  15.                      "Ź"=>"zzz",
  16.                      "ˇ"=>"azz",
  17.                      "ł"=>"lzz",
  18.                      "Ł"=>"lzz",
  19.                      "ż"=>"zz",
  20.                      "Ż"=>"zz",
  21.                      "ć"=>"czz",
  22.                      "Ć"=>"czz",
  23.                      "ń"=>"nzz",
  24.                      "Ń"=>"nzz",
  25.                      "Ę"=>"ezz",
  26.                      "ę"=>"ezz",
  27.                      "ó"=>"ozz",
  28.                      "Ó"=>"ozz"
  29.                );
  30.  
  31.  
  32.                foreach ($InArray as $Value) {
  33.                        reset($Columns);
  34.            $TmpArrayValue="";
  35.                        foreach ($Columns as $TmpValue)
  36.                            $TmpArrayValue.=" ".strtolower(strtr($Value[$TmpValue],$SortTrans));
  37.                            
  38.                        $TmpArray[$Index++] = substr($TmpArrayValue,1);
  39.                }
  40.  
  41.  
  42.                uasort($TmpArray,'strnatcmp');
  43.        if ($SortType>0) $TmpArray=array_reverse($TmpArray,TRUE);
  44.  
  45.                $Index = 0;
  46.  
  47.        while (list ($key, $val) = each ($TmpArray))
  48.            $ResultArray[$Index++] = $InArray[$key];
  49.            
  50.        return $ResultArray;
  51.    }
  52.  
  53. //wywołanie takie
  54. $sor_searchs = SortMultiArrayMultiLevel($uns_searchs,array(0=>'title'),0);
  55. ?>


Może uda Ci się to przerobić na swoje potrzeby. Ta funkcja sortowała po tablice wielowymiarowe po określonym polu w tablicy.
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: 5.10.2025 - 02:07