欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php數(shù)組去除空值函數(shù)分享

 更新時(shí)間:2015年02月02日 14:57:52   投稿:hebedich  
本文給大家分享一個(gè)使用php制作數(shù)組去除空值函數(shù),非常實(shí)用,推薦給大家,希望大家能夠喜歡。

對于一個(gè)一維的php數(shù)組,如何清除其中值為空的元素呢?直接的辦法是foreach循環(huán)一下,一個(gè)個(gè)判斷排除。不過這個(gè)方法還是略顯復(fù)雜,下面分享一下今天看到的一個(gè)方法,非常簡潔

復(fù)制代碼 代碼如下:

/**
 * 方法庫-數(shù)組去除空值
 * @param string $num  數(shù)值
 * @return string
 */
public function array_remove_empty(&$arr, $trim = true) {
    if (!is_array($arr)) return false;
    foreach($arr as $key => $value){
        if (is_array($value)) {
            self::array_remove_empty($arr[$key]);
        } else {
            $value = ($trim == true) ? trim($value) : $value;
            if ($value == "") {
                unset($arr[$key]);
            } else {
                $arr[$key] = $value;
            }
        }
    }
}

是不是非常實(shí)用的函數(shù)呢,希望大家能夠喜歡。

相關(guān)文章

最新評論