php create multidimensional array from flat one

后端 未结 5 2037
时光说笑
时光说笑 2020-12-18 11:21

I have an array like this:

 \'foo\', 1 => \'bar\', ..., x => \'foobar\' );
?>

What is the fas

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 12:08

    Try this:

    $out = array();
    $cur = &$out;
    foreach ($array as $value) {
        $cur[$value] = array();
        $cur = &$cur[$value];
    }
    $cur = null;
    
    print_r($out);
    

    Grabbed it from another post.

提交回复
热议问题