[nycphp-talk] Input as array names
Michael Hernandez
sequethin at gmail.com
Tue Aug 25 15:40:08 EDT 2009
On Tue, 2009-08-25 at 15:27 -0400, Hall, Leam wrote:
> Okay, here's one of the places I don't really get and can use some
> help on. On my text processing script I'm going to slurp up host
> names. They come in as the first, counting from 0, element. I can
> explode and create the array, which gives me a string:
>
> $hostname[1] = somehost.example.com
>
> I can safely get rid of the ".example.com" bit, leaving $hostname[1]
> as "somehost". What I need to understand is how to take $hostname[1]
> and make it an array in it's own right so I can assign it a list of
> numbers.
>
With variable variable names,
if $hostname[1] = somehost
$$hostname[1] = array();
now you have an array named $somehost
--Mike H
PS I didn't try it, don't hate me :)
More information about the talk
mailing list