php 恢复阵列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 恢复阵列相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> restore_array<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$arr</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$arr</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$arr</span>; <span style="color: #66cc66;">}</span>
<span style="color: #0000ff;">$c</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$new</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/list"><span style="color: #000066;">list</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$key</span>, <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">)</span> = <a href="http://www.php.net/each"><span style="color: #000066;">each</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$arr</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><a href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$new</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$c</span><span style="color: #66cc66;">]</span> = restore_array<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #0000ff;">$new</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$c</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$value</span>; <span style="color: #66cc66;">}</span>
<span style="color: #0000ff;">$c</span>++;
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$new</span>;
<span style="color: #66cc66;">}</span>
以上是关于php 恢复阵列的主要内容,如果未能解决你的问题,请参考以下文章