我有PeopleSearch类,它具有所有静态方法而不是一个方法。当我打电话给这个功能时,我会收到低于
的例外情况array_walk() expects parameter 2 to be a valid callback, function 'setUserRequestStatus' not found or invalid function name
以下是我的工作代码
class PeopleSearch {
public static function searchPeople($client = null) {
$inputs = Request::get('data');
$data['User'] = [];
$result = $client->search(self::prepare_search_params_people($inputs));
if (!empty($result) && count($result['hits']['hits']) > 0) {
$userArray = array_column($result['hits']['hits'], '_source');
// check user friend requests
$requestSents = FriendRequest::get_friend_requests($inputs['User']['id'], array_column(array_column($result['hits']['hits'], '_source'), 'id'))->toArray();
array_walk($userArray,'setUserRequestStatus',array_column($requestSents, 'request_to'));
echo "<pre>";
print_r($userArray);
exit;
}
}
public function setUserRequestStatus($user, $key, $requests_sent_to) {
$user['request_sent'] = in_array($user['id'], $requests_sent_to) ? true : false;
}
}
答案 0 :(得分:1)
根据手册,请用下面的代码替换您的代码
array_walk($ userArray,array(&#39; self&#39;,&#39; setUserRequestStatus&#39;));
希望这有帮助