php如何判断数组为“空”?
<?php
$code=file_get_contents("index.html"); preg_match_all("#<style[^>]*>(.*)</style>#isU",$code,$result);
print_r($result);
if(empty($result[1])){
echo "empty";
}
?>

解决方案 »

  1.   

    <?php
        $code=file_get_contents("index.html");    preg_match_all("#<style[^>]*>(.*)</style>#isU",$code,$result);
        print_r($result);
        if($result[1] == "" || !isset($result[1])){
            echo "empty";
        }
    ?>
      

  2.   

    不是存在$result[1][0]这个元素么,怎么会空呢
      

  3.   


    结果还是没有显示empty,空白字符?
      

  4.   

    如果非要判定$result[1][0]里面不包含,css语法代码可以这样试试if(str_replace(array("\n", "\r", ' '), '', $result[1][0]) == '')
    {
      echo 'EMPTY!';
    }
      

  5.   

    首先得把问题简化一下,你的数组是由 preg_match_all 产生的,所以只可能是两维数组。
    即是形如这样的数组 
    $ar = array(
     0 => array(0 => 'a'),
     1 => array(0 => ''),
    );
    $p = join('', $ar[1]);
    if(empty($p)) {
      echo 'empty';
    }当数组是多维的情况就复杂了,需要递归
      

  6.   

    <?php
    $code=file_get_contents("index.html"); preg_match_all("#<style[^>]*>(.*)</style>#isU",$code,$result);
    print_r($result);
    $p=join("",$result[1]);
    if(trim($p)==""){
    echo "empty";
    }
    ?>没有写==""还是会echo empty;谢谢版主
      

  7.   

    回 #7楼 当$p = array(0);时
    $p = join('', $p);
    if(empty($p)) {
      echo 'empty';
    }
    仍能执行  不能判断数组为空!!!直接用count()就Ok