Hi I have an array like this:
array(
'Home' => array(
'About',
'Contact'
),
'News'
);
I wrote this to printing them:
function show($arr){
foreach($arr as $key => $value){
echo "\n<ul>\n<li>\n" . $key;
if( ! empty($value)){
if(is_array($value)){
show($value);
}else{
echo $value;
}
}
echo "\n</li>\n</ul>\n";
}
}
My problem is when I try to echo $value It’ll print something like this:
Home
0About
1Contact
0News
I tried to echo $key where the echo $value is here now and I understood it’s the key index which is gonna write before the News field or any field that is not an array. I fixed it with turning the single fields to this:
array(
'Home' => array(
'About' => **array()**,
'Contact' => **array()**
),
'News' => **array()**
);
But I don’t want to define additional empty arrays!
Peace Out!
I would say you have to change the place of you echo (of the $key). If it’s not an array, you don’t care about the key, right ?