【发布时间】:2013-10-08 12:54:29
【问题描述】:
我有一个包含类名及其基类的数组。结构如下:
$list[0] = array("class"=>"ckEditor", "base"=>"domTextArea");
$list[1] = array("class"=>"ComboBox", "base"=>"Control");
$list[2] = array("class"=>"Control", "base"=>"");
$list[3] = array("class"=>"domTextArea", "base"=>"Control");
..
... so on up to 50 classes
问题是数组没有按照继承结构排序。在这种情况下,Control 类必须在顶部。 PHP中是否有任何函数可以根据父子关系对该结构进行排序。结果数组必须如下所示:
$list[0] = array("class"=>"Control", "base"=>"");
$list[1] = array("class"=>"domTextArea", "base"=>"Control");
$list[2] = array("class"=>"ckEditor", "base"=>"domTextArea");
$list[3] = array("class"=>"ComboBox", "base"=>"Control");
编辑:如果有人能建议一种算法来对这种结构进行排序,那也会很有帮助。
【问题讨论】:
-
你可以为它写一个自定义函数,默认函数不会知道那个层次结构
标签: php algorithm class sorting inheritance