0

I want to create a multidimensional array based on an xml file. the file only includes menu,menu->link and menu->submenu,menu->submenu->link. I want an multidimensional array to be looked like this.

array()  
0=>menu1  
  0=>submenu1  
  1=>sublink1  
1=>link1  
2=>menu2  
  0=>submenu1  
  1=>sublink1
  2=>submenu2  
  3=>sublink2
3=>link2  
....  
....  

the xml code is given here:

<page> 
  <title>Examination Remuneration</title>  

  <menu title ="Home" link="http://">  
    <submenu title="About" link="#">  
    </submenu>  
  </menu>  

  <menu title ="Data Entry" link="http://">  
    <submenu title="Form 1" link="#">  
    </submenu>  
    <submenu title="Form 2" link="#">  
    </submenu>  
  </menu>  
</page>  

what i have tried:

<?php  
  $main = simplexml_load_file("MENUU.xml");  
  $allmenu = array();  
  foreach ($main->menu as $menu) {  
    array_push($allmenu,$menu["title"]);
    foreach($menu->submenu as $submenu){  
         //dont know what to do here :(
    }
    array_push($allmenu,$menu["link"]);
  }
  var_dump($allmenu);
?>  

The problem is I cannot find how to push multi dimension and another problem is I dont know how many submenu a menu can have. Any kind of help is appreciated and TIA.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.