PHP Perm Missing Element
function permMissingElement($a): int
{
    sort($a);

    foreach ($a as $k => $v) {
        if ($v !== $k + 1) {
            return $k + 1;
        }
    }

    return count($a) + 1;
}

This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.