Array_filter and empty()

后端 未结 5 1373
梦毁少年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 18:05

    You can use just array_filter() function without callback:

    Remove empty array elements in PHP

    $arr = array("PHP", "HTML", "CSS", "", "JavaScript", null, 0);
    print_r(array_filter($arr)); // removing blank, null, false, 0 (zero) values
    

    Result:

    Array
    (
        [0] => PHP
        [1] => HTML
        [2] => CSS
        [4] => JavaScript
    )
    

提交回复
热议问题