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;)

0 comments:

Post a Comment

 
Top