Hard to explain, and let me show an example.
while (exists($username)) { if (!is_numeric(substr($username, -1, 1))) { $username = "{$username}0"; } $username++; } return $username;
You get: test, test1, test2 and so on