Re: Arrays as pointers?
| From: | DL Neil | Date: | Fri, 25 Jan 2002 22:27:27 +0000 |
| Subject: | Re: Arrays as pointers? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-81989@lists.php.net to get a copy of this message | ||
v0idnull,
[surely you don't think of yourself as a nonentity twice over?]
> A friend of mine showed me this code recently.
>
> function firstLogin_string() {
> mt_srand(make_seed());
> $pool = "AaBbCcDdEeFfGgHhIiJjKkLlM";
> $length = 26;
> for($i=0; $i < $length; $i++) {
> $key .= $pool[mt_rand(0,strlen($pool)-1)];
> }
> return $key;
> }
>
> 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. I've never seen this done before. What is this method
> called and what other neat tricks can you do in respect to this?
I'm not sure if it has a special name. A string is an array of characters.
I think you will find that you can use curly brackets/braces to identify a character/byte position
within a
string too - check it out in the manual.
The strings/arrays ($pool and $key) are not "Arrays of pointers" - what did you mean?
=dn