Remove NULL, FALSE, and '' - but not 0 - from a PHP array

后端 未结 9 2376
一生所求
一生所求 2020-12-09 02:15

I want to remove NULL, FALSE and \'\' values .

I used array_filter but it removes the 0\' s also.

9条回答
  •  醉话见心
    2020-12-09 02:53

    From http://php.net/manual/en/function.array-filter.php#111091 :

    If you want to remove NULL, FALSE and Empty Strings, but leave values of 0, you can use strlen as the callback function:

    array_filter($array, 'strlen');
    

提交回复
热议问题