0

经过一天的尝试解决这个问题,我不得不认输。

需要将层次结构格式化为报告/csv,其中缩进/层次结构正确,我需要一个接受数组的php函数,并创建如下层次结构。我知道起始节点是“销售”;

//[so]  [activity]  [milestone] [compleated]
    array(
        array("Sales", "Motor", "Documentation", "10%"),
        array("Sales", "Motor", "Communication", "15%"),
        array("Sales", "Motor", "Metro file", "30%"),
        array("Sales", "Motor", "Training", "33%"),
        array("Sales", "Motor", "Client Services", "23%"),
        array("Motor", "Documentation", "Doc revamp", "42%"),
        array("Motor", "Documentation", "SLA", "33%"),
        array("Motor", "Documentation", "KRA", "25%")
    )

Sales           
    Motor       
        Documentation           10%
            Doc revamp          43%
            SLA                 33%
            KRA                 25%
        Communication           15%
        Metro file              30%
        Training                33%
        Client Services         23%

Sales           
xx Motor        
xxx Documentation           10%
xxxx Doc revamp         43%
xxxxx SLA                   33%
xxxxx KRA                   25%
xxxx Communication          15%
xxxx Metro file             30%
xxxx Training               33%
xxxx Client Services        23%
4

1 回答 1

0

对数组进行排序(它似乎已经排序)。

将 $last_so $last_activity $last_milestone 初始化为 null;

循环遍历数组中的所有条目。

提取$so、$activity、$milestone;

当 $so 发生变化时(通过与 $last_so 比较来检测)输出 $so 作为第一个标头,并将 $last_activity $last_milestone 重置为 null;

当 $activity 将输出 $activity 更改为第二个 header 时,并将 $last_milestone 重置为 null;;

当 $milestone 更改输出 $milestone 作为第三个标头

输出第四列的百分比。

现在将 $last_so, .. etc 更新为 $So, .. etc。

继续循环。

于 2013-09-01T10:29:20.003 回答