Passing object method to array_map()

前端 未结 2 1285
天命终不由人
天命终不由人 2020-12-29 21:21
    class theClass{
         function doSomeWork($var){
            return ($var + 2);
         }

         public $func = \"doSomeWork\";

         function theFunc         


        
2条回答
  •  难免孤独
    2020-12-29 22:10

    The following code provides an array of emails from an $users array which contains instances of a class with a getEmail method:

        if(count($users) < 1) {
            return $users; // empty array
        }
        return array_map(array($users[0], "getEmail"), $users);
    

提交回复
热议问题