Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> dzialania na tablicach
palermos
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 27.09.2006

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


Mam taką tablice

Kod
Array
(
        [1] => Array
        (
            [id] => 1
            [data] => 2006-09-21
            [kwota] => 150.06
        )

    [2] => Array
        (
            [id] => 1
            [data] => 2006-10-03
            [kwota] => 4812.23
        )

    [3] => Array
        (
            [id] => 1
            [data] => 2006-10-04
            [kwota] => 3484.58
        )

    [4] => Array
        (
            [id] => 1
            [data] => 2006-10-05
            [kwota] => 460088.92
        )

    [5] => Array
        (
            [id] => 2
            [data] => 2006-10-01
            [kwota] => 123.00
        )

    [6] => Array
        (
            [id] => 2
            [data] => 2006-10-05
            [kwota] => 913547.00
        )

    [7] => Array
        (
            [id] => 2
            [data] => 2006-10-10
            [kwota] => 503552.64
        )

    [8] => Array
        (
            [id] => 2
            [data] => 2006-10-13
            [kwota] => 2981869.78
        )

    [9] => Array
        (
            [id] => 2
            [data] => 2006-10-15
            [kwota] => 11128.43
        )

    [10] => Array
        (
            [id] => 2
            [data] => 2006-10-25
            [kwota] => 13695.23
        )

)


Wyswietlając tabele ma byc posortowana po dacie (a ta tablica nie jest posortowana a nie wiem jak sie sortuje tablice względem danej kolumny) ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
matipl
post
Post #2





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 6.05.2003
Skąd: Gdańsk

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


odpowiedź można znaleźć w manualu php (array_multisort" title="Zobacz w manualu php" target="_manual), a dokładnie polecam komentarze.

  1. <?php
  2. function sortArray($data, $columnName) {
  3. if (!empty($data)) {
  4. foreach ($data as $key => $row) {
  5.  $column[$key] = $row[$columnName];
  6. }
  7. array_multisort($column, SORT_ASC, $data);
  8. }
  9. return $data;
  10. }
  11. ?>
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 Aktualny czas: 11.10.2025 - 08:52