12-29-2007, 02:34 PM
|
#13 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
|
Quote:
Originally Posted by Wildhoney
I always found it a bit odd accessing characters in a string as you would items in an array. I've always been tempted to use str_split to make it make sense.
|
Wildhoney, I don't see any advantages in using str_split() instead of accessing directly the characters. Actually, there are no differences when using {} or [] except of it's much faster because it's a language construct and str_split() is a function. sort(), array_combine(), and all other functions explicitly expect an array as an argument and wouldn't work in most of the cases with strings properly. So why do prefer to have a 'real' array even though it's slower and does only make sense if you need to perform actions on that array. Perhaps there are not any big differences (Of course that depends on the length of the string!) but imagine you're using it str_split() in a loop with one million iterations.  I guess the 'little' difference might be significant.
|
|
|
|