getUsers($comments); foreach ($comments as $key => $comment) { $comments[$key]['owner'] = $users[$comment['owner_id']] ?? null; $comments[$key]['to_user'] = $users[$comment['to_user_id']] ?? null; } return $comments; } public function getUsers(array $comments) { $ownerIds = kg_array_column($comments, 'owner_id'); $toUserIds = kg_array_column($comments, 'to_user_id'); $ids = array_merge($ownerIds, $toUserIds); return $this->getShallowUserByIds($ids); } }