Home > php教程 > php手册 > 是否为空函数改造

是否为空函数改造

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:34:51
Original
1122 people have browsed it

是否为空函数改造来函数来源于php手册http://php.net/manual/zh/function.empty.php 无 ?php//是否为空 可判断多维数组 默认0认为非空 $type=1时0认为空function is_empty($multiarray,$type='') { if(is_array($multiarray) and !empty($multiarray)){ $tmp

是否为空函数改造 来函数来源于php手册http://php.net/manual/zh/function.empty.php
<?php
//是否为空 可判断多维数组 默认0认为非空 $type=1时0认为空
function is_empty($multiarray,$type='') {
    if(is_array($multiarray) and !empty($multiarray)){
        $tmp = array_shift($multiarray);
        if(!is_empty($multiarray) or !is_empty($tmp)){return false;}
        return true;
    }
    if(is_numeric($multiarray) && empty($type)){return false;}//当type为空时 视0为非空
    if(empty($multiarray)){return true;}
    return false;
}
//是否为空 可判断字符和一维数组 0认为非空
function is_blank($value) {
    return empty($value) && !is_numeric($value);
}
$testCase = array (    
0 => '',
1 => "",
2 => null,
3 => array(),
4 => array(array()),
5 => array(array(array(array(array())))),
6 => array(array(), array(), array(), array(), array()),
7 => array(array(array(), array()), array(array(array(array(array(array(), array())))))),
8 => array(null),
9 => 'not empty',
10 => "not empty",
11 => array(array("not empty")),
12 => array(array(),array("not empty"),array(array())),
12 => '0'
);
foreach ($testCase as $key => $case ) {
    echo "$key  is_empty= ".is_empty($case)."<br>";
}
foreach ($testCase as $key => $case ) {
    echo "$key  is_empty= ".is_blank($case)."<br>";
}
?> 
Copy after login
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