PHP Built Multidimensional Array after explode function -


i try found function build multidimensional array after explode.

for example : here create array explode.

$str = 'root/foo/bar/file.jpg'; $ar = explode('/', $str); 

$ar => array('root', 'foo' , 'bar', 'file.jpg');

then want ouput :

array(3) {   ['root']=>        ['foo']=>            ['bar']=> "file.jpg" } 

any idea ?

thx

here 1 way problem can approached.

<?php  $str = 'root/foo/bar/file.jpg';  $parts = explode("/", $str); $leaf = array_pop($parts); $tree = array(); $branch = &$tree; foreach($parts $v){     $branch[$v] = array();     $branch = &$branch[$v]; } $branch = $leaf;  print_r($tree); 

try here


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -