Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Enter your code here, enjoy!
- $array = [
- '105' => [
- 'title' => 'Truck',
- 'nrcount' => 0,
- 'template_id' => 105,
- 'department_name' => 'Asset Management',
- 'department_id' => 78,
- 'subcategories' => [
- '183' => [
- 'title' => 'Light Duty',
- 'nrcount' => 0,
- 'code' => 'TRKLT',
- 'description' => 'Light Duty Truck',
- 'department_id' => 78,
- 'project_template_name' => 'Light Duty',
- 'flag_auto_accept' => 0,
- 'behaviors' => 'equipment'
- ],
- '184' => [
- 'title' => 'Medium Duty',
- 'nrcount' => 0,
- 'code' => 'TRKMD',
- 'description' => 'Medium Duty Truck.',
- 'department_id' => 78,
- 'project_template_name' => 'Medium Duty',
- 'flag_auto_accept' => 0,
- 'behaviors' => 'equipment'
- ]
- ]
- ],
- '114' => [
- 'title' => 'Trailer',
- 'nrcount' => 0,
- 'template_id' => 114,
- 'department_name' => 'Asset Management',
- 'department_id' => 78,
- 'subcategories' => [
- '186' => [
- 'title' => 'Single Axle',
- 'nrcount' => 0,
- 'code' => 'TRAILS',
- 'description' => 'Single Axle Trailer',
- 'department_id' => 78,
- 'project_template_name' => 'Single Axle',
- 'flag_auto_accept' => 0,
- 'behaviors' => 'material',
- ]
- ]
- ],
- '115' => [
- 'title' => 'Tractor',
- 'nrcount' => 0,
- 'template_id' => 115,
- 'department_name' => 'Asset Management',
- 'department_id' => 78,
- 'subcategories' => [
- '134' => [
- 'title' => 'Light Duty',
- 'nrcount' => 0,
- 'code' => 'TRALHT',
- 'description' => 'Tractor Light Duty',
- 'department_id' => 78,
- 'project_template_name' => 'Light Duty',
- 'flag_auto_accept' => 0,
- 'behaviors' => 'equipment| material'
- ],
- '135' => [
- 'title' => 'Medium Duty',
- 'nrcount' => 0,
- 'code' => 'TRAMED',
- 'description' => 'Tractor Medium Duty',
- 'department_id' => 78,
- 'project_template_name' => 'Medium Duty',
- 'flag_auto_accept' => 0,
- 'behaviors' => 'material'
- ]
- ]
- ]
- ];
- $aOpts = array('restrict_behaviors' => ['equipment', 'infrastructure']);
- $templateListingFiltered = array_filter($array, function($category) use ($aOpts) {
- $category['subcategories'] = array_filter($category['subcategories'], function($subcategory) use($aOpts) {
- if(count(array_intersect($aOpts['restrict_behaviors'], explode('|', $subcategory['behaviors']))) > 0) {
- return true;
- }
- return false;
- });
- print_r($category['subcategories']);
- return count($category['subcategories']) > 0;
- });
- echo "final\n";
- print_r($templateListingFiltered);
- // foreach( $templateListingFiltered as $key => $value ){
- // echo $value."\n";
- // }
- // function RecursiveWrite($array) {
- // foreach ($array as $vals) {
- // echo $vals['title'] . "\n";
- // foreach ($vals['subcategories'] as $sub) {
- // echo $sub['title'] . "\n";
- // }
- // echo "\n\n";
- // }
- // }
- //RecursiveWrite($templateListingFiltered);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement