温馨提示×

php取出数组空值的方法是什么

PHP
小亿
84
2024-02-21 09:22:19
栏目: 编程语言

在PHP中可以使用array_filter()函数来过滤数组中的空值。下面是一个示例代码:

$arr = array("a", "b", "", "c", null, "d");

// 使用array_filter()函数过滤数组中的空值
$arr = array_filter($arr, function($value) {
    return $value !== "" && $value !== null;
});

print_r($arr);

在上面的示例中,array_filter()函数会将数组中的空字符串和null值过滤掉,最终输出结果为array("a", "b", "c", "d")

0