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';
}
这是因为你有一个空字符串数组,它不是空数组。这是因为你有一个空字符串数组,这不是空数组。这是因为数组元素中有键,但其中没有值,因此被视为非空。这是因为数组元素中有键,但其中没有值,因此被视为非空。好的。谢谢但是,检查上述数组是否为空的更好方法是什么?好的。谢谢但是,检查上述数组是否为空的更好方法是什么?