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";
}
?>
<?php
$code=file_get_contents("index.html"); preg_match_all("#<style[^>]*>(.*)</style>#isU",$code,$result);
print_r($result);
if(empty($result[1])){
echo "empty";
}
?>
$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";
}
?>
结果还是没有显示empty,空白字符?
{
echo 'EMPTY!';
}
即是形如这样的数组
$ar = array(
0 => array(0 => 'a'),
1 => array(0 => ''),
);
$p = join('', $ar[1]);
if(empty($p)) {
echo 'empty';
}当数组是多维的情况就复杂了,需要递归
$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;谢谢版主
$p = join('', $p);
if(empty($p)) {
echo 'empty';
}
仍能执行 不能判断数组为空!!!直接用count()就Ok