如何建立一個PHP函數,將這個代碼轉換成HTML菜單 這是後我通過AJAX遞歸陣列菜單PHP
list[0][id] 55
list[1][id] 69
list[2][children][0][id] 67
list[2][children][1][id] 68
list[2][id] 57
做出的功能和這裏就是我進入數組功能
Array
(
[0] => Array
(
[id] => 55
[children] => Array
(
[0] => Array
(
[id] => 67
[children] => Array
(
[0] => Array
(
[id] => 57
[children] => Array
(
[0] => Array
(
[id] => 68
)
)
)
[1] => Array
(
[id] => 69
)
)
)
)
)
)
我已經tryed此功能,但它不能正常工作
function tomenu($arr){
$html = '<ul>'.PHP_EOL;
foreach ($arr as $v){
$html .= '<li>' . $v['id'];
if (array_key_exists('children', $v)){
$html .= $this->tomenu($v['children']);
}
$html .= '</li>'.PHP_EOL;
}
$html .= '</ul>'.PHP_EOL;
return $html;
}
請幫助我。
是代碼甚至是一個數組我還沒有測試此代碼?我沒有看到任何$或s =只是看起來像文本。 –
'不行'不是錯誤信息。如果它不起作用,它會做什麼? – DaveRandom
請顯示定義/啓動你的數組的php代碼。 –