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
kefirek
post
Post #2





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

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


  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. );
  14.  
  15.  
  16. function array_search_i($str,$array){
  17. foreach($array as $key => $value) {
  18. if(array_search($str, $value)){
  19. return $key;
  20. }
  21. }
  22. return false;
  23. }
  24.  
  25. $key = array_search_i(1, $tablica);
  26.  
  27. echo $tablica[$key]['url'];
  28. echo $tablica[$key]['name'];
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: 9.10.2025 - 02:34