-1

我有关于我的 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 | 
4

1 回答 1

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>';

?>
于 2013-01-29T03:35:45.127 回答