Remove Empty Values from PHP Array

In PHP, you can use the array_filter() function to filter out empty values in an array. Here is an example code:

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

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

print_r($arr);

In the example above, the array_filter() function removes empty strings and null values from the array, resulting in the output array(“a”, “b”, “c”, “d”).

bannerAds