I have these arrays for my navbar.
$all_pages = array(
'home' => 'Home',
'about' => 'About us',
'gallery' => array(
'photo-gallery' => 'Photo Gallery',
'video-gallery' => 'Video Gallery'
),
'contact' => 'Contact us'
);
I want to obtain an array like this
'home' => 'Home',
'about' => 'About us',
'photo-gallery' => 'Photo Gallery',
'video-gallery' => 'Video Gallery'
'contact' => 'Contact us'
So far I've tried this code
$gall_pages = $all_pages['gallery'];
$pages = $all_pages;
unset($pages['gallery']);
$pages = array_merge($pages, $gall_pages);
But I get this kind of array
'home' => 'Home',
'about' => 'About us',
'contact' => 'Contact us'
'photo-gallery' => 'Photo Gallery',
'video-gallery' => 'Video Gallery'
Is there any way to insert those gallery pages in between 'about' & 'contact'?
Solution with
array_walk_recursivewhich eliminates the need forifcheck inforeach:Fiddle here.