newbtophp Posted September 7, 2010 Share Posted September 7, 2010 $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 https://forums.phpfreaks.com/topic/212775-quickermore-simpler-way-of-doing-this/ Share on other sites More sharing options...
Psycho Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212775-quickermore-simpler-way-of-doing-this/#findComment-1108311 Share on other sites More sharing options...
newbtophp Posted September 7, 2010 Author Share Posted September 7, 2010 Thanks mjdamato I used your first example Link to comment https://forums.phpfreaks.com/topic/212775-quickermore-simpler-way-of-doing-this/#findComment-1108411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.