Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Łączenie tablic
Kshyhoo
post
Post #1





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Jak mam połączyć dwie tablice:
  1. array(23) {
  2. [0]=>
  3. array(2) {
  4. ["id"]=>
  5. string(1) "1"
  6. ["name"]=>
  7. string(16) "jeden"
  8. }
  9. [1]=>
  10. array(2) {
  11. ["id"]=>
  12. string(1) "2"
  13. ["name"]=>
  14. string(17) "dwa"
  15. }
  16. [2]=>
  17. array(2) {
  18. ["id"]=>
  19. string(1) "3"
  20. ["name"]=>
  21. string(18) "trzy"
  22. }
  23. [3]=>
  24. array(2) {
  25. ["id"]=>
  26. string(1) "4"
  27. ["name"]=>
  28. string(14) "cztery"
  29. }
  30. }
  31.  
  32. array(1) {
  33. [0]=>
  34. array(23) {
  35. ["a1"]=>
  36. string(1) "2"
  37. ["a2"]=>
  38. string(1) "0"
  39. ["a3"]=>
  40. string(1) "0"
  41. ["a4"]=>
  42. string(1) "0"
  43. }
  44. }

Chciałbym je połączyć w jedną. Umiem, jeżeli są takie same, tu poległem.
Nie muszę mieć unikalnych kluczy, mogą być z pierwszej tablicy.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


  1. $a1 = [
  2. [
  3. 'id'=> '1',
  4. 'name' => 'test1'
  5. ],
  6. [
  7. 'id'=> '2',
  8. 'name' => 'test2'
  9. ],
  10. ];
  11.  
  12. $a2 = [
  13. [
  14. 'a1' => 'a1',
  15. 'a11' => 'a11'
  16. ]
  17. ];
  18.  
  19. var_dump(array_replace_recursive($a1, $a2));
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 - 21:15