开发者

How to convert one dimensional array into multidimensional?

开发者 https://www.devze.com 2023-04-04 05:38 出处:网络
i have an array like $arr($name=>\"vinu\",$street0=>\"xxx\",$street1=>\"yyy\"). i need to convert this as

i have an array like

$arr($name=>"vinu",$street0=>"xxx",$street1=>"yyy").

i need to convert this as

$arr1($name=>"vinu",$street=>arra开发者_Go百科y("xxx","yyy")).

How can i do this?


like

foreach($ary as $k => $v)
    if(preg_match("~(.+?)(\d+)$~", $k, $m))
        $out[$m[1]][$m[2]] = $v;
    else
        $out[$k] = $v;

basically, if a key is "something and digits" put its value into result[something][digits] otherwise simply copy the value into the result array

0

精彩评论

暂无评论...
验证码 换一张
取 消