Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przerobienie tablicy na inną
damianooo
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

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


Potrzebuję przerobić taką tablicę:

  1. array(80) {
  2. [0]=>
  3. array(7) {
  4. ["meet_id"]=>
  5. int(1)
  6. ["host"]=>
  7. string(12) "FC Barcelona"
  8. ["guest"]=>
  9. string(11) "Real Madryt"
  10. ["hostType"]=>
  11. int(0)
  12. ["guestType"]=>
  13. int(2)
  14. ["username"]=>
  15. string(6) "Damian"
  16. ["term"]=>
  17. string(23) "Wtorek,12-12-2016,21:00"
  18. }
  19. [1]=>
  20. array(7) {
  21. ["meet_id"]=>
  22. int(2)
  23. ["host"]=>
  24. string(15) "Atletico Madryt"
  25. ["guest"]=>
  26. string(10) "Sevilla FC"
  27. ["hostType"]=>
  28. int(1)
  29. ["guestType"]=>
  30. int(2)
  31. ["username"]=>
  32. string(6) "Damian"
  33. ["term"]=>
  34. string(23) "Wtorek,12-12-2016,21:00"
  35. }
  36. ...


na taką:

  1. array(10) {
  2. [0] => array(3) {
  3. ["meet_id"] => 1,
  4. ["host"] => "team 1",
  5. ["guest"] => "team 2",
  6. ["types"] => array(10) {
  7. ["0-1","0-0","2-1","0-1","-","2-1","0-1","0-0","-","2-1"]
  8. }
  9. }
  10. [1] .... itd.
  11. }



Jak to zrobić ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Pyton_000
post
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Raczej coś w ten deseń:

  1. <?php
  2.  
  3. foreach ($result as $detail) {
  4. if(in_array($detail['meet_id'],$types)) {
  5. $types[$detail['meet_id']]['types'][] = $detail['hostType'].' - '.$details['guestType']
  6. continue;
  7. }
  8. $types[$detail['meet_id']] = [
  9. 'meet_id' => $detail['meet_id'],
  10. 'host' => $detail['host'],
  11. 'guest' => $detail['guest'],
  12. 'types' => [
  13. $detail['hostType'].' - '.$details['guestType']
  14. ],
  15. ];
  16. }
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 - 01:48