我有一个 API 调用的返回值,该调用将类别树作为一个平面数组提供,其中父/子关系用重复的字符串拼写出来。一个小样本:
[0] => Architecture & Street Scenes
[1] => Architecture & Street Scenes/Architectural Detail
[2] => Architecture & Street Scenes/Architectural Detail/Cast or Wrought Ironwork
[3] => Architecture & Street Scenes/Architectural Detail/Cast or Wrought Ironwork/Balconies
[4] => Architecture & Street Scenes/Architectural Detail/Cast or Wrought Ironwork/Fences
[5] => Architecture & Street Scenes/Courtyards
[6] => Architecture & Street Scenes/Exteriors & Street Scenes
[7] => Architecture & Street Scenes/Interiors
[8] => Architecture & Street Scenes/Street Lamps
[9] => Art & Culture
[10] => Art & Culture/Dance
有没有一种优雅的方式使用 PHP 从那里消除重复并通过拥有子数组来表达关系?
[0] => Architecture & Street Scenes
[0] => Architectural Detail
[0] => Cast or Wrought Ironwork
[1] => Cast or Wrought Ironwork
[0] => Balconies
[1] => Fences
[1] => Courtyards
[2] => Exteriors & Street Scenes
[3] => Interiors
[4] => Street Lamps
[1] => Art & Culture
[0] => Dance