简体   繁体   中英

Convert 1-dimensional array with n items, into n-dimensional array

How to convert this:

$arr = array('item1','item2','item3','item4','...');

to this:

$arr2['item1']['item2']['item3']['item4']['...'] = $something;
$arr2 = $something;
foreach (array_reverse($arr) as $key) {
    $arr2 = array($key => $arr2);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM