Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Wyciaganie elementu z tablicy wielowymiarowej
motorolka24
post
Post #1





Grupa: Zarejestrowani
Postów: 90
Pomógł: 0
Dołączył: 21.04.2007

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


Jak można wyciągnąć z poniższej tablicy element array( "id" => "1","url" => "aa.html","name" => "aa") podając id = 1. Najlepiej żeby było to bez użycia pętli lub rekurencji
  1. $tablica = array( array( "id" => "1",
  2. "url" => "aa.html",
  3. "name" => "aa"
  4. ),
  5. array( "id" => "2",
  6. "url" => "bb.html",
  7. "name" => "bb",
  8. ),
  9. array( "id" => "3",
  10. "url" => "cc.html",
  11. "name" => "cc"
  12. )
  13. );
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
darko
post
Post #2





Grupa: Zarejestrowani
Postów: 2 885
Pomógł: 463
Dołączył: 3.10.2009
Skąd: Wrocław

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


Bez użycia pętli?
  1. $tablica = array(
  2. array( "id" => "1",
  3. "url" => "aa.html",
  4. "name" => "aa"
  5. ),
  6. array( "id" => "2",
  7. "url" => "bb.html",
  8. "name" => "bb",
  9. ),
  10. array( "id" => "3",
  11. "url" => "cc.html",
  12. "name" => "cc"
  13. )
  14. );
  15.  
  16. $tmp = array_values($tablica);
  17. print_r($tmp[0]);
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 - 21:48