Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

php怎么除去数组里的空值

作者:恋你如初   发布日期:2024-01-13   浏览:693

可以使用array_filter()函数来除去数组中的空值。该函数会返回一个新的数组,其中包含原数组中所有不为空的元素。

以下是一个示例:

$array = array("foo", "", "bar", "baz", null, "qux");

// 使用array_filter()函数除去空值
$newArray = array_filter($array);

// 输出新数组
print_r($newArray);

输出结果为:

Array
(
    [0] => foo
    [2] => bar
    [3] => baz
    [5] => qux
)

在上述示例中,原数组中的空字符串、null值都被除去,只保留了非空值。

上一篇:php怎么求两个数组差值

下一篇:php怎么修改数组的元素

大家都在看

php session用法

phpisset函数

php后端

php爬虫框架

php读取csv文件

php 三元表达式

php文件加密

php 拆分字符串

php pcntl

php ||

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站