Skip to content
Advertisement

Remove empty values from PHP array but keep 0

I have an array

JavaScript

I used:-

array_filter()

to remove the null values and it returns

JavaScript

array_filter() removes null value and also ‘0’ value.

Any builtin function is available in PHP to remove NULL values only.

Advertisement

Answer

Assumption: I think you want to remove NULL as well as empty-strings/values '' from your array. (What i understand from your desired output)

You have to use array_filter() with strlen()

JavaScript

Output:-

https://eval.in/926585

https://eval.in/926595

https://eval.in/926602

Refrence:-

PHP: array_filter – Manual

PHP: strlen – Manual

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement