Home > php教程 > PHP源码 > body text

从数组中删除空白的元素(包括只有空白字符的元素)

WBOY
Release: 2016-06-08 17:28:23
Original
1470 people have browsed it

从数组中删除空白的元素(包括只有空白字符的元素)

<script>ec(2);</script>

 /**
 *
 *
 * @param array $arr
 * @param boolean $trim
 */
function delete_empty(& $arr, $trim = true)
{
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            delete_empty($arr[$key]);
        } else {
            $value = trim($value);
            if ($value == '') {
                unset($arr[$key]);
            } elseif ($trim) {
                $arr[$key] = $value;
            }
        }
    }
}

 

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template