我有关于PHP的数据,我将从这些数据中创建树状菜单:
$data[] = "IT/managerial/software/kasubsie/Moro/Konsolidasi Server";
$data[] = "IT/managerial/software/kasubsie/Moro/Setting Server";
$data[] = "IT/managerial/software/kasubsie/Setting Server/Moro";
如何使用列生成表格:
| id | parent_id | name |
答案 0 :(得分:1)
这很有效。以此为基础。主要逻辑是preg_split
每行数据。希望这有帮助!
<?php
$data = array();
$data[] = "IT/managerial/software/kasubsie/Moro/Konsolidasi Server";
$data[] = "IT/managerial/software/kasubsie/Moro/Setting Server";
$data[] = "IT/managerial/software/kasubsie/Setting Server/Moro";
$value_array = array();
echo '<table border="1">';
foreach ($data as $key => $value) {
echo '<tr>';
$value_array = preg_split("/\//", $value);
foreach ($value_array as $table_cell_value) {
echo '<td>' . $table_cell_value . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>