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;
      }
    }
Rizwan Saleem
  • 904
  • 11
  • 28

1 Answers1

2

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

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

Hope this helps

Rizwan Saleem
  • 904
  • 11
  • 28
  • thanks to answer but after implementing your answer i get this error "Undefined variable: this" – Rizwan Saleem Nov 28 '17 at 10:32
  • Your callback function is static so you may use the below code snippet array_walk($array, array('self', 'walkFunction')); –  Nov 28 '17 at 10:39
  • Please give a up vote if you find the answer is helpful –  Nov 28 '17 at 10:42