dongxingchang9345 2014-07-04 13:34 采纳率: 0%
浏览 92

从PHP数组中删除false值的更短方法

Presently I'm using array_values(array_filter($arr)) to remove false values from an array.

It feels like there's most likely a built-in function that does this more tersely.

  • 写回答

1条回答 默认 最新

  • dongliao6491 2014-07-04 13:35
    关注

    Sure.

    function f($arr) {return array_values(array_filter($arr));}
    

    Now you can do:

    $b = f($a);
    

    Much more terse! Much less readable.

    array_values(array_filter(..)) is very explicit as to what it does. This is many times more important than terseness.

    评论

报告相同问题?