Jump to content

menu array


BODEKA

Recommended Posts

$menu_arr = array( 
'a' => array('name'=>'A', 'path'=>'a.php'),  

'b' => array('name'=>'B', 'path'=>'b.php', 'submenu'=> 
    array(    'b_a' => array('name'=>'B_A', 'path'=>'b_a.php'),  

            'b_b' => array('name'=>'B_B', 'path'=>'b_b.php','submenu'=> 
                            array(    'x' => array('name'=>'X', 'path'=>'x.php'), 
                                    'y' => array('name'=>'Y', 'path'=>'y.php'))),                  
                                                                                                                             
             'b_c'     => array('name'=>'B_C', 'path'=>'b_c.php'))), 

'c' => array('name'=>'C', 'path'=>'c.php') 
); 


function get_path($arr, $filename, $retval = '') {  

     foreach($arr as $key=>$value) {   
     
     
        $retval .= $value['name'].'&'.$value['path'].' | ';  
      
        if($key==$filename) { 
            return $retval; 
        }      
      
      
        if( isset($value['submenu']) ) {  
         
            get_path($value['submenu'], $filename, $retval); 
        }      
          
    } // end foreach     
}  

I have been struggling to find a way to get the

the path as follows:

 

For example

 

echo get_path($menu_arr, 'b_c' ); 

 

 

should spit out:

B&b.php|B_C&b_c.php

 

or

 

echo get_path($menu_arr, 'Y' ); 

B&b.php|B_B&b_b.php|Y&y.php

 

Link to comment
https://forums.phpfreaks.com/topic/82531-menu-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.