Jump to content

Quicker/more simpler way of doing this?


Recommended Posts

          $array = array();
          for ($i = 97; $i < 123; $i++) {
              $array[] = chr($i);
          for ($i = 65; $i < 91; $i++) {
              $array[] = chr($i);


Its quite time consuming looping, perhaps combine in 1 or?

Link to comment
Share on other sites

Well, you can reference characters in a string the same way you reference elements in an array. So the simplest solution would be to simply define a string with all the characters

$array = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


However, if you need to keep it as an array construct and/or need it to be done programatically, then this might be more efficient

$array = array_merge(range(97, 122), range(65, 90));
$array = array_map("chr", $array);


However, there are many different possible solutions and I can't say which would be more efficient without testing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.