我有这个数组:
$categories = array(
array('id' => 1, 'parent' => 0, 'name' => 'Category A'),
array('id' => 2, 'parent' => 0, 'name' => 'Category B'),
array('id' => 3, 'parent' => 0, 'name' => 'Category C'),
array('id' => 4, 'parent' => 0, 'name' => 'Category D'),
array('id' => 5, 'parent' => 0, 'name' => 'Category E'),
array('id' => 6, 'parent' => 2, 'name' => 'Subcategory F'),
array('id' => 7, 'parent' => 2, 'name' => 'Subcategory G'),
array('id' => 8, 'parent' => 3, 'name' => 'Subcategory H'),
array('id' => 9, 'parent' => 4, 'name' => 'Subcategory I'),
array('id' => 10, 'parent' => 9, 'name' => 'Subcategory J'),
);
结果我需要这个:(对于 $categories 数组中的每个类别都很简单,需要一个完整结构的链接)
$result = array(
'10' => 'Category D/Subcategory I/Subcategory J',
'9' => 'Category D/Subcategory I',
'8' => 'Category C/Subcategory H',
'7' => 'Category B/Subcategory G',
'6' => 'Category B/Subcategory F',
'5' => 'Category E',
'4' => 'Category D',
'3' => 'Category C',
'2' => 'Category B',
'1' => 'Category A')
);
之后,我可以通过 $result[9] 调用链接并获取路径“D 类/子类 I”谢谢您的建议。