How to remove empty element or NULL values from PHP array?
Sponsored Links
Okay let say that we have the following array
|
1 |
$arr = Array ( [0] => 'php' [1] => 'tutorial' [2] => 'programming' [3] => ); |
In our array above we have an empty element which is [3], so how to get rid of it? will that’s not a problem I will explain it here.
After searching and digging on the net I found 4 to 10 lines of code but I believed that there should be a simple possible solution for this, then I tried searching over php.net site and I found this very useful php array function array_filter().

To remove NULL values
|
1 |
$arr = array_filter($arr, 'strlen'); |
To remove all false values
|
1 |
$arr = array_filter($arr); |
That’s it and it works like a charm;)
Sponsored Links
Stay connected with us:
Advertise here
I’m a graphic/web designer and web developer living in Philippines who is passionate on contributing to the web development industry. I love the Web.