Advertisement
Guest User

Untitled

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