Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Enter your code here, enjoy!
- $array = array('105' => array(
- 'title' => 'Truck',
- 'subcategories' => Array (
- '183' => Array (
- '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' => Array (
- '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'
- )
- ),
- 'nrcount' => 0,
- 'template_id' => 105,
- 'department_name' => 'Asset Management',
- 'department_id' => 78
- ),
- '114' => Array (
- 'title' => 'Trailer',
- 'subcategories' => Array (
- '186' => Array (
- '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',
- ),
- 'nrcount' => 0,
- 'template_id' => 114,
- 'department_name' => 'Asset Management',
- 'department_id' => 78
- ),
- '115' => Array (
- 'title' => 'Tractor',
- 'subcategories' => Array (
- '134' => Array (
- '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'
- ),
- '135' => Array (
- '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'
- )
- ),
- 'nrcount' => 0,
- 'template_id' => 115,
- 'department_name' => 'Asset Management',
- 'department_id' => 78
- )
- ));
- $aOpts = array('restrict_behaviors' => ['equipment', 'infrastructure']);
- $templateListingFiltered = array_filter($array, function($category) use ($aOpts) {
- $category['subcategories'] = array_filter($category['subcategories'], function($subcategory) use($aOpts) {
- $aa = explode('|', $subcategory['behaviors']);
- print_r($aa);
- if(count(array_intersect($aOpts['restrict_behaviors'], explode('|', $subcategory['behaviors']))) > 0) {
- return true;
- }
- return false;
- });
- return count($category['subcategories']) > 0;
- });
- // 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