我们在实际运用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>
以上代码就是PHP删除数组空白元素的具体实现方法,希望大家能够保存收藏起来,方便日后使用。