Ciao,
ho un problema a creare un menu automaticamente avendo questo array:
Uso una funzione ricorsiva ma ho difficoltà ad avere id e name della categoria nello stesso momento per fare un URL tipo :<a href='ciao.php?cat=sotto1&id=3'codice:array(1) { [0]=> array(2) { ["name"]=> string(9) "categorie" ["categorie"]=> array(6) { [0]=> array(2) { ["name"]=> string(6) "sotto1" ["id"]=> string(1) "3" } [1]=> array(3) { ["name"]=> string(6) "sotto2" ["id"]=> string(1) "4" ["sotto2"]=> array(1) { [0]=> array(2) { ["name"]=> string(11) "sottosotto1" ["id"]=> string(1) "5" } } } [2]=> array(2) { ["name"]=> string(6) "sotto3" ["id"]=> string(1) "6" } [3]=> array(2) { ["name"]=> string(6) "sotto4" ["id"]=> string(1) "7" } [4]=> array(2) { ["name"]=> string(6) "sotto5" ["id"]=> string(1) "8" } [5]=> array(3) { ["name"]=> string(6) "sotto6" ["id"]=> string(1) "9" ["sotto6"]=> array(2) { [0]=> array(3) { ["name"]=> string(11) "sottosotto1" ["id"]=> string(2) "10" ["sottosotto1"]=> array(1) { [0]=> array(2) { ["name"]=> string(16) "sottosottosotto1" ["id"]=> string(2) "12" } } } [1]=> array(2) { ["name"]=> string(11) "sottosotto2" ["id"]=> string(2) "11" } } } } } }
Questa è una breve funzione ricorsiva da cui penso si possa partire...ma mi trovo in difficoltà...qualcuno sa aiutarmi???Codice PHP:function process($arr)
{
foreach ($arr as $key => $value)
{
if(is_array($value))
{
process($value)." -";
}
else
{
echo htmlspecialchars($value). " ";
}
}
}
Ciao
Alberto

Rispondi quotando

prova così allora