Array_filter and empty()

后端 未结 5 1519
梦毁少年i
梦毁少年i 2020-12-19 17:33

Warning: array_filter() expects parameter 2 to be a valid callback, function \'empty\' not found or invalid function name....

Why is e

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 17:45

    I think a better solution exist and I found it reading the doc about array_filter

    See this comment : https://www.php.net/manual/fr/function.array-filter.php#111091

    
    

    I only allow myself to post it because I think it's a very elegant solution.

    Also, as array_filter itself already filter null or false value as a default callback, this code work too :

    $array = array('apple', '', 'watermelon');
    var_dump(array_filter($array));
    
    ----
    Output : 
    array(2) { [0]=> string(5) "apple" [2]=> string(10) "watermelon" }
    

提交回复
热议问题