Salve a tutti!
Ho il seguente codice che genera un array contenente la struttura ad albero di tutte le pagine del sito.
Questa funzione gestisce l'output della funzione di cui sopracodice:function PagesTree($array, $pid = 0) { $result = array(); foreach( $array as $id => $item ) { if( $item['parent_id'] == $pid ) { $result[$id] = array( 'id' => $id, 'title' => $item['title'], 'parent_id' => $item['parent_id'], ); // recursion $children = $this->PagesTree( $array, $id ); if( $children ) { $result[$id]['child'] = $children; } } } return $result; }
Vorrei che questa funzione mi generasse un array con l'id e il titolo della pagina ordinato in base alla struttura gerarchica che viene già generata dalla funzione PageOptionsTree();codice:function PageOptionsTree($array, $parent = "") { $str = ""; foreach ($array as $id => $item) { $str .= '<option value="' . $id . '" />' . $parent . $item['title'] . '</option>'; // recursive for children if (isset($item['child'])) { $str .= $this->PageOptionsTree($item['child'], $parent . ''); } } return $str; }
Qualcuno sarebbe in grado di aiutarmi?
Grazie 1000 in anticipo

Rispondi quotando