>>10
To clarify, I'm not disagreeing that
>>2's use of
str_split is stupid (or that
>>2 is stupid in the whole), but rather that there are cases where it
is useful to use
str_split.
PHP strings are already arrays of chars, and can already be used as such.
This is not correct. PHP strings support indexing via
operator[] (and
operator{} pre-PHP6), but they are
not arrays. This can be illustrated with a simple example:
$ php -r 'print_r( is_array( "asd" ) ? "Arrays\n" : "Not arrays\n" );'
Not arrays
While they have the same indexing syntax as arrays, they lack other features, like iterative functionality --
$ php -r 'foreach( "asd" as $a ) echo( "$a\n" );'
Warning: Invalid argument supplied for foreach() in Command line code on line 1
$ php -r 'foreach( str_split( "asd" ) as $a ) echo( "$a\n" );'
a
s
d
In conclusion please read SICP.