Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How does it make you feel?

Name: Anonymous 2008-08-19 8:01


$file_id = $db->escape_string(md5_file($file));

Name: >11 2008-08-19 11:38

>>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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List