$prev) { $pos++; $prev = $n; } else if ($prev > $n) { $trial[$pos] = ($trial[$pos] + 9) % 10; $pos++; } else { $prev = $n; } $trial[$pos] = ($trial[$pos] + 1) % 10; }