gpt4 book ai didi

php - 删除数组中的空值元素

转载 作者:可可西里 更新时间:2023-11-01 12:25:28 26 4
gpt4 key购买 nike

Array
(
[0] => 0 //value is int 0 which isn;t empty value
[1] => //this is empty value
[2] => //this is empty value
)

我想把上面的数组改成下面的样子,谁能帮帮我?

非常感谢

Array
(
[0] => 0
)

最佳答案

您可以使用 array_filter删除空值(null、false、''、0):

array_filter($array);

如果您不想从数组中删除 0,请参阅@Sabari 的回答:

array_filter($array,'strlen');

关于php - 删除数组中的空值元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9062871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com