Using array_filter function in thinkphp5

The array_filter function is used in

thinkphp5, and the second parameter is wrong. Ask the god how to modify it. Thank you

<?php  
namespace app\controller;  
class Abs
{
    public function index(){
        function abc($value){
            if($value!==""){
                return true;
            }else{
                return false;
            }
        }

        $data = [
            "a"=>1,
            "b"=>0,
            "c"=>true,
            "d"=>false,
            "e"=>0,
            "f"=>"",
            "d"=>null
        ];
    
        return array_filter($data,"abc");
    }
}

error report:
array_filter () expects parameter 2 to be a valid callback, function "abc" not found or invalid function name

Php
Nov.09,2021

is related to namespace. Just specify namespace.

return array_filter($data,'\app\controller\abc');

you can write this way

public function index(){
        

        $data = [
            'a'=>1,
            'b'=>0,
            'c'=>true,
            'd'=>false,
            'e'=>0,
            'f'=>'',
            'd'=>null
        ];
    
        return array_filter($data,function($value){
            if($value!==''){
                return true;
            }else{
                return false;
            }
        });
    }

what is the specific error message?


the second parameter requires a callback function, which abc does not have
function abc ()
{
return true;
};

Menu