Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. <?php
  2. //Enter your code here, enjoy!
  3.  
  4. $array = array('105' => array(
  5. 'title' => 'Truck',
  6. 'subcategories' => Array (
  7. '183' => Array (
  8. 'title' => 'Light Duty',
  9. 'nrcount' => 0,
  10. 'code' => 'TRKLT',
  11. 'description' => 'Light Duty Truck',
  12. 'department_id' => 78,
  13. 'project_template_name' => 'Light Duty',
  14. 'flag_auto_accept' => 0,
  15. 'behaviors' => 'equipment'
  16. ),
  17. '184' => Array (
  18. 'title' => 'Medium Duty',
  19. 'nrcount' => 0,
  20. 'code' => 'TRKMD',
  21. 'description' => 'Medium Duty Truck.',
  22. 'department_id' => 78,
  23. 'project_template_name' => 'Medium Duty',
  24. 'flag_auto_accept' => 0,
  25. 'behaviors' => 'equipment'
  26. )
  27. ),
  28. 'nrcount' => 0,
  29. 'template_id' => 105,
  30. 'department_name' => 'Asset Management',
  31. 'department_id' => 78
  32. ),
  33. '114' => Array (
  34. 'title' => 'Trailer',
  35. 'subcategories' => Array (
  36. '186' => Array (
  37. 'title' => 'Single Axle',
  38. 'nrcount' => 0,
  39. 'code' => 'TRAILS',
  40. 'description' => 'Single Axle Trailer',
  41. 'department_id' => 78,
  42. 'project_template_name' => 'Single Axle',
  43. 'flag_auto_accept' => 0,
  44. 'behaviors' => 'material',
  45. ),
  46. 'nrcount' => 0,
  47. 'template_id' => 114,
  48. 'department_name' => 'Asset Management',
  49. 'department_id' => 78
  50. ),
  51. '115' => Array (
  52. 'title' => 'Tractor',
  53. 'subcategories' => Array (
  54. '134' => Array (
  55. 'title' => 'Light Duty',
  56. 'nrcount' => 0,
  57. 'code' => 'TRALHT',
  58. 'description' => 'Tractor Light Duty',
  59. 'department_id' => 78,
  60. 'project_template_name' => 'Light Duty',
  61. 'flag_auto_accept' => 0,
  62. 'behaviors' => 'equipment'
  63. ),
  64. '135' => Array (
  65. 'title' => 'Medium Duty',
  66. 'nrcount' => 0,
  67. 'code' => 'TRAMED',
  68. 'description' => 'Tractor Medium Duty',
  69. 'department_id' => 78,
  70. 'project_template_name' => 'Medium Duty',
  71. 'flag_auto_accept' => 0,
  72. 'behaviors' => 'material'
  73. )
  74. ),
  75. 'nrcount' => 0,
  76. 'template_id' => 115,
  77. 'department_name' => 'Asset Management',
  78. 'department_id' => 78
  79. )
  80. ));
  81.  
  82.  
  83. $aOpts = array('restrict_behaviors' => ['equipment', 'infrastructure']);
  84. $templateListingFiltered = array_filter($array, function($category) use ($aOpts) {
  85. $category['subcategories'] = array_filter($category['subcategories'], function($subcategory) use($aOpts) {
  86. $aa = explode('|', $subcategory['behaviors']);
  87. print_r($aa);
  88. if(count(array_intersect($aOpts['restrict_behaviors'], explode('|', $subcategory['behaviors']))) > 0) {
  89. return true;
  90. }
  91. return false;
  92. });
  93. return count($category['subcategories']) > 0;
  94. });
  95.  
  96. // foreach( $templateListingFiltered as $key => $value ){
  97. // echo $value."\n";
  98. // }
  99.  
  100. function RecursiveWrite($array) {
  101. foreach ($array as $vals) {
  102. echo $vals['title'] . "\n";
  103. foreach ($vals['subcategories'] as $sub) {
  104. echo $sub['title'] . "\n";
  105. }
  106. echo "\n\n";
  107.  
  108.  
  109. }
  110. }
  111.  
  112. RecursiveWrite($templateListingFiltered);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement