Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> dziwny problem, petla foreach
deniol13
post
Post #1





Grupa: Zarejestrowani
Postów: 190
Pomógł: 2
Dołączył: 30.11.2009

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


mam tablice, zapisana w zmiennej $forums
  1. (
  2. [0] => Array
  3. (
  4. [category_id] => 1
  5. [category_name] => test
  6. [category_order] => 0
  7. [forum_id] => 2
  8. [forum_name] => test2
  9. [forum_description] => asd
  10. [parent_cat] => 1
  11. [forum_order] => 2
  12. )
  13.  
  14. [1] => Array
  15. (
  16. [category_id] => 2
  17. [category_name] => kat2
  18. [category_order] => 0
  19. [forum_id] => 3
  20. [forum_name] => test3
  21. [forum_description] => aaaaaa
  22. [parent_cat] => 2
  23. [forum_order] => 3
  24. )
  25.  
  26. [2] => Array
  27. (
  28. [category_id] => 1
  29. [category_name] => test
  30. [category_order] => 0
  31. [forum_id] => 1
  32. [forum_name] => test1
  33. [forum_description] => testowe forum
  34. [parent_cat] => 1
  35. [forum_order] => 3
  36. )
  37.  
  38. )


i kod

  1. [/php]$i = 0;
  2. foreach( $forums AS $category )
  3. {
  4. $cid = $category['category_id'];
  5. $forums_rebuild[ $cid ] = array( 'category_name' => $category['category_name'], 'forums' => array() );
  6.  
  7. $forums_rebuild[ $cid ]['forums'][$i] = array( 'forum_name' => $category['forum_name'] );
  8.  
  9. $i++;
  10. }[php]


i $forums_rebuild zawiera nei wszystkie fora tylko
  1. (
  2. [1] => Array
  3. (
  4. [category_name] => test
  5. [forums] => Array
  6. (
  7. [2] => Array
  8. (
  9. [forum_name] => test1
  10. )
  11.  
  12. )
  13.  
  14. )
  15.  
  16. [2] => Array
  17. (
  18. [category_name] => kat2
  19. [forums] => Array
  20. (
  21. [1] => Array
  22. (
  23. [forum_name] => test3
  24. )
  25.  
  26. )
  27.  
  28. )
  29.  
  30. )
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 02:27