Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Łączenie tablic [php]
charlie-cherry
post 28.01.2011, 18:42:22
Post #1





Grupa: Zarejestrowani
Postów: 93
Pomógł: 5
Dołączył: 15.12.2007

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


Mam dwie tablice, które chcę połączyć.

Tablica 1:

  1.  
  2. (
  3. [scenariusz] => Array
  4. (
  5. [0] => Array
  6. (
  7. [id] => 7344
  8. [tytul] => Tytuł Książki1
  9. )
  10.  
  11. )
  12.  
  13. [rysunki] => Array
  14. (
  15. [0] => Array
  16. (
  17. [id] => 7344
  18. [tytul] => Tytuł Książki1
  19. )
  20.  
  21. )
  22.  
  23. )


Tablica 2

  1. (
  2. [scenariusz] => Array
  3. (
  4. [0] => Array
  5. (
  6. [id] => 3563
  7. [tytul] => Tytul Ksiązki 2
  8. )
  9.  
  10. [1] => Array
  11. (
  12. [id] => 6201
  13. [tytul] => Tytuł Książki 3
  14. )
  15. )
  16. )


Nie wiem jak je połączyć, by otrzymać taką tabelę jak na dole. Array_push dodaje po kluczach "rysunki" i scenariusz"
klucz [0], Array_merge też odpada. Byłbym wdzięczny za sugestie.

  1.  
  2. [scenariusz] => Array
  3. (
  4. [0] => Array
  5. (
  6. [id] => 7344
  7. [tytul] => Tytuł Książki1
  8. )
  9.  
  10. [1] => Array
  11. (
  12. [id] => 3563
  13. [tytul] => Tytul Ksiązki 2
  14. )
  15.  
  16. [2] => Array
  17. (
  18. [id] => 6201
  19. [tytul] => Tytuł Książki 3
  20. )
  21. )
  22.  
  23. [rysunki] => Array
  24. (
  25. [0] => Array
  26. (
  27. [id] => 7344
  28. [tytul] => Tytuł Książki1
  29. )
  30.  
  31. )
  32.  
  33. )
  34.  


Go to the top of the page
+Quote Post
Wicepsik
post 28.01.2011, 18:59:32
Post #2





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

Ostrzeżenie: (20%)
X----


  1. foreach($tablica2 as $k=>$v){
  2. foreach($v as $s){
  3. $tablica1[$k][] = $s;
  4. }
  5. }


--------------------
Go to the top of the page
+Quote Post
charlie-cherry
post 28.01.2011, 19:04:22
Post #3





Grupa: Zarejestrowani
Postów: 93
Pomógł: 5
Dołączył: 15.12.2007

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


Bingo, to właśnie to. Wielkie dzięki.
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 05:37