I could be wrong about this, but here goes:

Strings are in fact arrays.  An array of characters.  The code your 
friend gave you manipulates this array in the same way that it would any 
"normal" array.  The only problem (not really a problem even) is that 
when dealing with character-based arrays from strings, braces 
("curlies") rather than brackets ("straights") should be used to delimit 
the index of the array element from the variable name itself.  In other 
words, the correct syntax for your code would have been:

for($i=0; $i < $length; $i++) {
                $key .= $pool{mt_rand(0,strlen($pool)-1)};
        }

It's all explained on this page (check halfway down the page where it 
says "String Access by Character"):   
http://www.php.net/manual/en/language.types.string.php

Hope this helps clarify what you're seeing.



On Thursday, January 24, 2002, at 04:57  PM, v0idnull wrote:

> look at the for loop. $pool is not an array but is being treated as 
> such and
> the key happens to be the position in $pool and it'll take that letter 
> and
> save it to $key.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to