Home >Backend Development >PHP Tutorial >大家帮忙看一下这段简单的代码哪里有问题

大家帮忙看一下这段简单的代码哪里有问题

WBOY
WBOYOriginal
2016-06-23 14:15:03999browse

    private function getUserInfo(callable $Human)    {        try {            $users = (new $Human)->getUser()['users'];            $underageUsers = [foreach ($users as $user) if ($user->age < 18) yield $user];                        list($userNames, $ages) = array_map(                function($value) {return array_column($value, array('userNames', 'ages'), default);},                 mb_convert_encoding($underageUsers, 'utf-8', 'gbk')            );                        return ['name' => $userNames, 'surname' => $ages];        } catch(Exception $e) {            error_log($e);        }    }


回复讨论(解决方案)

callable 是什么?给出定义!

callable 是一个提示占位符.
说明参数是可以调用的资源体 

这个代码真心时尚啊,一堆php 5.5的特性。

$underageUsers是一个数组,什么时候mb_convert_encoding可以接受一个数组作为参数了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn