Page 1 of 1

Getting the next char in a sequence

Posted: Thu Jan 04, 2007 10:54 am
by mabersold
Greetings all. I'm looking for a way of determining the next character in sequence, given a single character string ranging from a-z.

The way I'm currently doing it:

Given a single-character string $key, I get the next character in the sequence by doing this: $key2 = chr(ord($key) + 1). It works fine for my purposes thus far. I'm just wondering if there's a better/more efficient way of handling this.

For what it's worth, this line will probably only run once every time the script is called.

Posted: Thu Jan 04, 2007 11:02 am
by TheMoose
If you store $key somewhere else, or you've already used $key, you can use $key2 = ++$key

Careful though, using ++$key will overwrite $key as well (they'll be the same character).