fork download
  1. <?php
  2.  
  3. function create($list, &$result) {
  4. if (is_array($list) && !isset($list['category_id'])) {
  5. foreach ($list as $element) {
  6. create($element, $result);
  7. }
  8. } else {
  9. $result[$list['category_id']] = $list['name'];
  10. create($list['children'], $result);
  11. }
  12. }
  13.  
  14. $list = array(
  15. 'category_id' => 2,
  16. 'name' => 'Koffersenkisten',
  17. 'is_active' => 0,
  18. 'children' => array(
  19. 'category_id' => 40,
  20. 'name' => 'Muziek',
  21. 'is_active' => 0,
  22. 'children' => array(
  23. 'category_id' => 46,
  24. 'name' => 'Gitaar koffer',
  25. 'is_active' => 0,
  26. 'children' => array()
  27. ),
  28. 'category_id' => 51,
  29. 'name' => 'Electrische gitaar',
  30. 'is_active' => 1,
  31. 'children' => array()
  32. )
  33. )
  34. )
  35. )
  36. )
  37. );
  38. create($list, $result);
  39. var_dump($result);
  40.  
  41. ?>
Success #stdin #stdout 0.03s 13112KB
stdin
Standard input is empty
stdout
array(4) {
  [2]=>
  string(15) "Koffersenkisten"
  [40]=>
  string(6) "Muziek"
  [46]=>
  string(13) "Gitaar koffer"
  [51]=>
  string(18) "Electrische gitaar"
}