This the complet code, it's working just fine, adjust is as you need ;)
<?php
$pages_tree = array();
$pages_tree[0]['page_id'] = 300;
$pages_tree[0]['page_parent'] = 0;
$pages_tree[0]['page_name'] = 'MAIN 1';
$pages_tree[0]['depth_level'] = 1;
$pages_tree[0]['children'] = array(array("page_id"=>302, "page_parent"=>300, "page_name"=>'SUB 1', "depth_level"=>2, "children" => array(array("page_id"=>305, "page_parent"=>302, "page_name"=>'SUB-SUB 1', "depth_level"=>3), array("page_id"=>303, "page_parent"=>302, "page_name"=>'SUB-SUB 2', "depth_level"=>3))));
$pages_tree[1]['page_id'] = 301;
$pages_tree[1]['page_parent'] = 0;
$pages_tree[1]['page_name'] = 'MAIN 2';
$pages_tree[1]['depth_level'] = 1;
$pages_tree[1]['children'] = array(array("page_id"=>304, "page_parent"=>301, "page_name"=>'SUB 2', "depth_level"=>2));
echo '<pre>';
print_r($pages_tree);
echo '</pre>';
//////////////////////////////////////////////////////////////////////////
function flatten_array($array){
echo '<ul>';
$str = ''; //Appeneded string
$displayed = false; //Boolean show if the string is already print it or not
//Loop
foreach($array as $key => $val)
{
if(is_array($val))
{
if($str != ''){
echo '<il>' . $str . '</li>'; //Display the String after
$displayed = true; //Make the boolean true cuz the sring is already print it
}
//Send the child Array to the function again
flatten_array($val);
}
else
{
//Verify if the key if a page_id or page_name , so here you can add what you need (maybe depth_level or page_parent)
if($key == 'page_id') $str .= $val;
if($key == 'page_name') $str = $val . ' - ' . $str;
}
}
//Print the str if it not already display it
if($str != '' && $displayed != true) echo '<il>' . $str . '</li>';
echo '</ul>';
}
//////////////////////////////////////////////////////////////////////////////////
flatten_array($pages_tree);
?>