[nycphp-talk] Array Transformation Assistance.

David Krings ramons at
Mon Oct 2 16:46:35 EDT 2006


I usually create a second numerically indexed array that has as elements 
the key names. The numerical keys correspond to each other so that I only 
need a while loop and a counter to access each element of the source arrays 
that I then stick together as key/element pairs in a resulting array. I do 
not know the exact circumstance, but I needed to get two things out of a 
database that were related to each other and that had to be of the same 
count by design. Worked great, but today I'd use SQL and a join for this, 
which works even better.


At 03:04 PM 10/2/2006, you wrote:
>Go ahead chuckle it up. But, yes, I need this one little one.
>I begin with a numerically indexed array of elements (could be any length):
>$master_names  = array("Joe", "Sam", "Tom" ... )
>I need to rename all the array elements as to make a matching consistent 
>associative array.
>And... the keys in the associative array must be derived from combining 
>the name of the array
>(in this example 'master_names') with the correct former index value 
>appended on the end of
>each new key:
>$master_names = array('master_names0'=>"Joe", 'master_names1'=>"Sam, 
>'master_names2'=>"Tom" ... )
>Yes, that is it.
>Warmest regards,
>Peter Sawczynec
>Technology Director
>_Design & Interface
>_Database Management
><mailto:ps at>ps at
>New York PHP Community Talk Mailing List
>NYPHPCon 2006 Presentations Online
>Show Your Participation in New York PHP

More information about the talk mailing list