1

I have PeopleSearch class that has all static method instead of one method. Whne i call this function then i receive exceptio that is below

array_walk() expects parameter 2 to be a valid callback, function 'setUserRequestStatus' not found or invalid function name 

Below is my working code

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; } } 
5
  • 1
    Change 'setUserRequestStatus' with [$this, 'setUserRequestStatus'] Commented Nov 28, 2017 at 10:28
  • @splash58 thanks for help but after implementing your answer i get this error "Undefined variable: this" Commented Nov 28, 2017 at 10:31
  • 1
    stackoverflow.com/a/39375501/476 Commented Nov 28, 2017 at 10:35
  • ^ eval.in/909064 I missed that method is static Commented Nov 28, 2017 at 10:39
  • @splash58 thank you so much to help problem is solved through your provided link Commented Nov 28, 2017 at 10:42

1 Answer 1

2

As per the manual please replace your code with the below one

array_walk($userArray, array('self', 'setUserRequestStatus'));

Hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

thanks to answer but after implementing your answer i get this error "Undefined variable: this"
Your callback function is static so you may use the below code snippet array_walk($array, array('self', 'walkFunction'));
Please give a up vote if you find the answer is helpful

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.