根据我从问题中了解到的情况,您想编写一个显示 6 行的程序,如下所示:
类别:
-Something 1
table1,table2,
table3 -Something 2
table1,table2,
table3 -Something 3
table1,table2, table3
首先,您需要按 ASC 顺序形成行。
改变这样的事情:
Array(Category,
Category_something1,
Category_something2_table1,
Category_something2_table2,
Category_something2_table3,
Category_something2,
Category_something3_table1,
Category_something3_table2,
Category_something3_table3,
Category_something3,
Category_something1_table1,
Category_something1_table2,
Category_something1_table3,)
进入 :
Array(Category,
Category_something1,
Category_something1_table1,
Category_something1_table2,
Category_something1_table3,
Category_something2,
Category_something2_table1,
Category_something2_table2,
Category_something2_table3,
Category_something3,
Category_something3_table1,
Category_something3_table2,
Category_something3_table3,)
然后运行一个循环,将每个字符串拆分为 3。如果第二个值/第三个不存在,则打印为标题/类别,否则打印为项目/某物。
While(ArrayKey is not equal to count(Array))
{
SplitString(ArrayCurValue,"_",$VarValue1,$VarValue2,$VarValue3); //split current string into 3 vars where _ is present
if($VarValue2 == "")
{
Print "<b>",$VarValue1,"</b>";
}else{
if($VarValue3 == "")
{
Print " -",$VarValue2;
}else{
Print " -",$VarValue3;
}
}
}