public function getHatedPlayerId($hateRank) { $i = 0; $playerId = 0; $sorted = Utils::sortBy($this->hatelist, function ($obj) { return $obj->hate; }); $size = count($this->hatelist); if ($hateRank && $hateRank <= $size) { $i = $size - $hateRank; } else { $i = $size - 1; } if ($sorted && $sorted[$i]) { $playerId = $sorted[$i]->id; } return $playerId; }