NYCPHP Meetup

NYPHP.org

[nycphp-talk] Array Transformation Assistance.

Scott Mattocks scott at crisscott.com
Mon Oct 2 16:55:32 EDT 2006


Peter Sawczynec wrote:
> This is technically correct, thank you. Except your solution takes it for
> granted that 
> we always want the new associative array keys to be named
> 'master_names'.$index, but 
> that is not the case.
>  
> The new keys must take on the name of the original array variable name
> whatever it was, 
> more like so:

You would have to have the name of the array variable stored in another 
variable. Then you have to access the array with a variable variable.

${$array_name}[$array_name . $index] = $value;

Unfortunately, there is no way to get the name of a variable dynamically 
like that. You would have to have it hard coded somewhere.

Scott Mattocks



More information about the talk mailing list