我有一个像
Array
(
[0] => Array
(
[id] => 81
[cata_key] => 908cbbcb86a1cf64b67c96ff
[cata_name] => Lunch
[app_key] => 2fabc0d9447c6375657dead4
[parentid] => 0
[subcategories] => Array
(
)
)
[1] => Array
(
[id] => 80
[cata_key] => baac98b4e73c05ebbf45bdc6
[cata_name] => Break Fast
[app_key] => 2fabc0d9447c6375657dead4
[parentid] => 0
[subcategories] => Array
(
[0] => Array
(
[id] => 82
[cata_key] => 5970b7afc450ef3b24573de9
[cata_name] => Rise Products
[app_key] => 2fabc0d9447c6375657dead4
[parentid] => 80
[subcategories] => Array
(
[0] => Array
(
[id] => 83
[cata_key] => 82e36d8f821e14fc8db1d4da
[cata_name] => Dosha
[app_key] => 2fabc0d9447c6375657dead4
[parentid] => 82
[subcategories] => Array
(
[0] => Array
(
[id] => 84
[cata_key] => 49730020d850439dd7de8747
[cata_name] => Masala Dosha
[app_key] => 2fabc0d9447c6375657dead4
[parentid] => 83
[subcategories] => Array
(
)
)
)
)
)
)
)
)
)
我想从特定的内部数组 id 中找到根索引子数组的深度。例如我想从 parentid=0 找到根索引数组的深度,它应该是 1。从 parentId=0/80/82/83 开始的根索引子数组的深度应该是 4。
实际上我的目标是限制数组的深度。应该有深度限制。所以当任何人试图向这个数组添加一个子数组时,我们应该找出当前数组的深度。例如,数组深度限制为 4 ,并且任何人尝试在 cata_name= Masala Dosha 下添加子数组,深度已经达到并且不应允许添加新的子数组。但同时他可以在[cata_name] => Lunch下面添加一个子数组,因为它的深度只有1,深度限制是4。