function removeFriend() { $id = max(0, (int) $_POST['id']); $current_user = new CurrentUser(); if ($current_user->authorized) { if ($current_user->id != $id) { $user_following = $current_user->getFollowing(); $friend = Users::getById($id); /* @var $friend User */ $friend_followers = $friend->getFollowers(); if (isset($user_following[$id])) { unset($user_following[$id]); } if (isset($friend_followers[$current_user->id])) { unset($friend_followers[$current_user->id]); } $current_user->setFollowing($user_following); $friend->setFollowers($friend_followers); $friend->save(); $current_user->save(); } } }