php - multidimensional array from comma separated string -


im trying convert comma separated multidimensional array create menu structure of this.

this have already..

        ($i=0; $i < $count; $i++) {                 if($i > 0){                     array_push($tagmenu[0][$pretags[$i-1]], array($pretags[$i]=>array()));                 } else {                     array_push($tagmenu, array($pretags[$i]=>array()));                 }              } 

i have string

$tags = 'image,landscape,night'; 

and want this

array(       [images] = array (                  [landscape] = array(                                [night] = array ()                  )       ) 

i'm searching fingers off on this

$tags = 'image,landscape,night'; $newarray = array(); $wrkarray = &$newarray;  foreach(explode(',',$tags) $tag) {     $wrkarray[$tag] = array();     $wrkarray = &$wrkarray[$tag]; } unset($wrkarray); var_dump($newarray); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -