Home > Backend Development > PHP Tutorial > 请问php可以将一维转成多维吗?

请问php可以将一维转成多维吗?

WBOY
Release: 2016-06-06 20:14:31
Original
1203 people have browsed it

如:
$a=['a','b','c'];
希望得到结果

<code>var_dump($new)
'a'=>'b'=>'c'</code>
Copy after login
Copy after login

谢谢.

回复内容:

如:
$a=['a','b','c'];
希望得到结果

<code>var_dump($new)
'a'=>'b'=>'c'</code>
Copy after login
Copy after login

谢谢.

<code class="php">$a=['a','b','c','d','e','f','g'];
$last=null;
while($last=array_pop($a)) {
  if( null != $last ) array_push($a,[array_pop($a)=>$last]);
  if(count($a) </code>
Copy after login

Array
(

<code>[a] => Array
    (
        [b] => Array
            (
                [c] => Array
                    (
                        [d] => Array
                            (
                                [e] => Array
                                    (
                                        [f] => g
                                    )

                            )

                    )

            )

    )
</code>
Copy after login

)

我觉得不可以。

我建议写个递归函数,利用下标。递归特性太明显了。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template