Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klucz z tablicy wielowymiarowej
mk83
post
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 17.02.2005

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


Jak otrzymac klucz z tablic wielowymiarowej (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Zgadza sie -- nie sprawdzilem dzialania skryptu.

  1. <pre><?php
  2. $table2 = array( array( 'A' => 65, 'B' => 66 ), array( 'a' => 95, 'b' => 96, 'c' => 99 ), array( 'm' => array( 'f' => 0, 'g' => 1, 'h' => 2 ), 'n' =>array( 'f' => 0, 'g' => 1, 'h' => 2 ) ) );
  3.  
  4. function getAllKeysRecursively( $arrTable )
  5. {
  6. $arrReturnTable = array();
  7. foreach ( $arrTable as $key => $value )
  8. {
  9. if ( ! is_array( $value ) )
  10. {
  11. $arrReturnTable[] = $key;
  12. }
  13. else
  14. {
  15. $arrReturnTable[ $key ] = getAllKeysRecursively( $value );
  16. }
  17. }
  18.  
  19. return $arrReturnTable;
  20.  
  21. }
  22.  
  23. print_r( $table2 );
  24. $res = getAllKeysRecursively( $table2 );
  25. print_r( $res );
  26. ?></pre>

Rezultat:
Kod
Array
(
    [0] => Array
        (
            [0] => A
            [1] => B
        )

    [1] => Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [2] => Array
        (
            [m] => Array
                (
                    [0] => f
                    [1] => g
                    [2] => h
                )

            [n] => Array
                (
                    [0] => f
                    [1] => g
                    [2] => h
                )

        )

)
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: 26.12.2025 - 21:15