Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP空函数-关联数组_Php - Fatal编程技术网

PHP空函数-关联数组

PHP空函数-关联数组,php,Php,有人能解释为什么这是非空的吗 <?php $attributes=array("description"=>"","quantity"=>"","price"=>"","discount"=>""); if(empty($attributes)) echo 'empty'; else echo 'non empty'; exit; ?> 来自: 确定变量是否为空如果变量不存在或其值等于FALSE,则视为空。empty()如果变量不存在,

有人能解释为什么这是非空的吗

<?php

$attributes=array("description"=>"","quantity"=>"","price"=>"","discount"=>"");

if(empty($attributes))
   echo 'empty';
else
    echo 'non empty';
exit;

?>

来自:

确定变量是否为空如果变量不存在或其值等于FALSE,则视为空。empty()如果变量不存在,则不会生成警告

在这种情况下,变量
$attributes
存在并且不等于FALSE。因此
empty()
将返回布尔值
FALSE

检查它们是否都是空的,并回显消息:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}
要检查所有数组值是否为空:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}
要检查是否有任何数组值为空:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}
从:

确定变量是否为空如果变量不存在或其值等于FALSE,则视为空。empty()如果变量不存在,则不会生成警告

在这种情况下,变量
$attributes
存在并且不等于FALSE。因此
empty()
将返回布尔值
FALSE

检查它们是否都是空的,并回显消息:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}
要检查所有数组值是否为空:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}
要检查是否有任何数组值为空:

foreach ($attributes as $key => $value) {
    if (empty($value)) {
        echo "'$key' is empty\n";
    }
}
if(!array_filter($attributes)) {
    echo 'All values are empty';
}
if (array_search('', $attributes) !== FALSE) {
    echo 'One of the values in the array is empty';
}

这是因为你有一个空字符串数组,它不是空数组。

这是因为你有一个空字符串数组,这不是空数组。

这是因为数组元素中有键,但其中没有值,因此被视为非空。这是因为数组元素中有键,但其中没有值,因此被视为非空。好的。谢谢但是,检查上述数组是否为空的更好方法是什么?好的。谢谢但是,检查上述数组是否为空的更好方法是什么?