php 一维数组变多维

将下面的数组处理成下图的样子

$arr = ['a', 'b', 'c', 'd','e','f'];

这里写图片描述

<?php

$arr = ['a', 'b', 'c', 'd','e','f'];

$x = [];
$y = &$x; 
$value = 1234;

while ($key = current($arr)) {
    $y[$key] = [];

    $y = &$y[$key];
    next($arr);
    //echo $key;
}
$y = $value;

print_r($x);
?>
posted @ 2017-02-12 19:52  刘梦阳  阅读(691)  评论(0编辑  收藏  举报