我有一个多维数组,并且能够使用array_values()
.
但是,我也需要subNavigationItems
重新索引子数组。
这是我目前收到的array_values($arr)
:
array (
0 =>
array (
'navigationMenuId' => '1',
'parentNavigationMenuId' => '0',
'contentId' => '1',
'fullURL' => '/index',
'contentSlug' => 'index',
'contentAlias' => 'Index',
'navigationAnchor' => 'Home',
'navigationOrder' => '1',
'subNavigationItems' =>
array (
),
),
1 =>
array (
'navigationMenuId' => '2',
'parentNavigationMenuId' => '0',
'contentId' => '15',
'fullURL' => '/top-nav-1/index',
'contentSlug' => 'index',
'contentAlias' => 'Index',
'navigationAnchor' => 'Top Nav 1',
'navigationOrder' => '2',
'subNavigationItems' =>
array (
),
),
2 =>
array (
'navigationMenuId' => '3',
'parentNavigationMenuId' => '0',
'contentId' => '7',
'fullURL' => '/top-nav-2/index',
'contentSlug' => 'index',
'contentAlias' => 'Index',
'navigationAnchor' => 'Top Nav 2',
'navigationOrder' => '3',
'subNavigationItems' =>
array (
4 =>
array (
'navigationMenuId' => '4',
'parentNavigationMenuId' => '3',
'contentId' => '8',
'fullURL' => '/top-nav-2/sub-nav-1',
'contentSlug' => 'sub-nav-1',
'contentAlias' => 'Sub Nav 1',
'navigationAnchor' => 'Sub Nav 1',
'navigationOrder' => '1',
'subNavigationItems' =>
array (
),
),
5 =>
array (
'navigationMenuId' => '5',
'parentNavigationMenuId' => '3',
'contentId' => '10',
'fullURL' => '/top-nav-2/sub-nav-2',
'contentSlug' => 'sub-nav-2',
'contentAlias' => 'Sub Nav 2',
'navigationAnchor' => 'Sub Nav 2',
'navigationOrder' => '2',
'subNavigationItems' =>
array (
),
),
6 =>
array (
'navigationMenuId' => '6',
'parentNavigationMenuId' => '3',
'contentId' => '9',
'fullURL' => '/top-nav-2/sub-nav-3',
'contentSlug' => 'sub-nav-3',
'contentAlias' => 'Sub Nav 3',
'navigationAnchor' => 'Sub Nav 3',
'navigationOrder' => '3',
'subNavigationItems' =>
array (
),
),
7 =>
array (
'navigationMenuId' => '7',
'parentNavigationMenuId' => '3',
'contentId' => '11',
'fullURL' => '/top-nav-2/sub-nav-4',
'contentSlug' => 'sub-nav-4',
'contentAlias' => 'Sub Nav 4',
'navigationAnchor' => 'Sub Nav 4',
'navigationOrder' => '4',
'subNavigationItems' =>
array (
),
),
),
),
3 =>
array (
'navigationMenuId' => '8',
'parentNavigationMenuId' => '0',
'contentId' => '5',
'fullURL' => '/top-nav-3/index',
'contentSlug' => 'index',
'contentAlias' => 'Top Nav 3',
'navigationAnchor' => 'Top Nav 3',
'navigationOrder' => '4',
'subNavigationItems' =>
array (
),
),
4 =>
array (
'navigationMenuId' => '9',
'parentNavigationMenuId' => '0',
'contentId' => '6',
'fullURL' => '/top-nav-4/index',
'contentSlug' => 'index',
'contentAlias' => 'Top Nav 4',
'navigationAnchor' => 'Top Nav 4',
'navigationOrder' => '5',
'subNavigationItems' =>
array (
10 =>
array (
'navigationMenuId' => '10',
'parentNavigationMenuId' => '9',
'contentId' => '12',
'fullURL' => '/top-nav-4/sub-nav-1',
'contentSlug' => 'sub-nav-1',
'contentAlias' => 'Sub Nav 1',
'navigationAnchor' => 'Sub Nav 1',
'navigationOrder' => '1',
'subNavigationItems' =>
array (
),
),
11 =>
array (
'navigationMenuId' => '11',
'parentNavigationMenuId' => '9',
'contentId' => '13',
'fullURL' => '/top-nav-4/sub-nav-2',
'contentSlug' => 'sub-nav-2',
'contentAlias' => 'Sub Nav 2',
'navigationAnchor' => 'Sub Nav 2',
'navigationOrder' => '2',
'subNavigationItems' =>
array (
),
),
12 =>
array (
'navigationMenuId' => '12',
'parentNavigationMenuId' => '9',
'contentId' => '14',
'fullURL' => '/top-nav-4/sub-nav-3',
'contentSlug' => 'sub-nav-3',
'contentAlias' => 'Sub Nav 3',
'navigationAnchor' => 'Sub Nav 3',
'navigationOrder' => '3',
'subNavigationItems' =>
array (
),
),
),
),
5 =>
array (
'navigationMenuId' => '13',
'parentNavigationMenuId' => '0',
'contentId' => '4',
'fullURL' => '/top-nav-5/index',
'contentSlug' => 'index',
'contentAlias' => 'Top Nav 5',
'navigationAnchor' => 'Top Nav 5',
'navigationOrder' => '6',
'subNavigationItems' =>
array (
),
),
)
注意第一个嵌套数组索引是 4、5、6 和 7,第二个索引是 10、11 和 12。我需要它们都从 0 开始。如果函数这样做可以是一个无限递归函数。
如果您看到每个项目都有一个subNavigationItems
可能会填充更多东西的数组,那么我也需要将这些数组重新索引为 0。
关于我如何做到这一点的任何想法?