Home > php教程 > php手册 > PHP删除数组空白元素的具体实现方式分享

PHP删除数组空白元素的具体实现方式分享

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:06:42
Original
1293 people have browsed it

我们在实际运用PHP删除数组空白元素的具体代码如下:

<ol class="dp-xml">
<li class="alt"><span><span>function array_remove_empty(& $arr, $</span><span class="attribute"><font color="#ff0000">trim</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">true</font></span><span>)   </span></span></li>
<li class=""><span>{   </span></li>
<li class="alt">
<span>foreach ($arr as $</span><span class="attribute"><font color="#ff0000">key</font></span><span> =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> $value) {   </span>
</li>
<li class=""><span>if (is_array($value)) {   </span></li>
<li class="alt"><span>array_remove_empty($arr[$key]);   </span></li>
<li class=""><span>} else {   </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">value</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">trim</font></span><span>($value);   </span>
</li>
<li class="">
<span>if ($</span><span class="attribute"><font color="#ff0000">value</font></span><span> == '') {   </span>
</li>
<li class="alt"><span>unset($arr[$key]);   </span></li>
<li class=""><span>} elseif ($trim) {   </span></li>
<li class="alt"><span>$arr[$key] = $value;   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span>}   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span>}  </span></li>
</ol>
Copy after login

以上代码就是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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template