我有一個多維數組這樣多維數組
$role = array (
'Dashboard' => null,
'Students' =>
array (
'Admission' => array (0 => 'Entry' ,1 => 'Review' , 2 => 'Approved/Reject'
),
'Search' => null,
'AdvanceSearch' => null,
'Courses' => null
),
'HR' => array ('Settings' => null),
'Employee Management' => array (0 => 'Entry',1 => 'Association',2 => 'Search'),
'Employee Attendance' => null,
'Payroll' => array (0 => 'Generate Pay Slip',1 => 'Payroll Run' , 2 => 'Payroll Revert',3 => 'View Pay Slips'),
'Finance' => null,
'More' => null);
,我想用遞歸在我的HTML打印這個數組結果作爲
我試圖這樣做,但無法這樣做,因爲DIV沒有正確關閉.. 這裏是我試圖在我的HTML代碼
<?php
$child = 0;
function RecursiveWrite($array, $child) {
$parent_array_size = count($array);
foreach ($array as $key => $vals) {
if(is_array($vals)){
$inner_array_size = count($vals);
echo "<div class='main clear'><input type='checkbox'/> ".$key." ";
RecursiveWrite($vals,$child);
}else{
$child = 0;
if(is_numeric($key)){
echo " <div class='left'> <input type='checkbox' class=''/> ".$vals." </div></div>";
}else{
echo "<div class='clear'><input type='checkbox'/> ".$key." </div></div>";
}
}
//
}
}
RecursiveWrite($role, $child);
?>
這裏是working code
我怎樣才能得到這個任何建議......?
輸入數據結構是有點不一致。 – pQd