NYCPHP Meetup

[nycphp-talk] Array Transformation Assistance.

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


Hi,

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.

David


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" ... )
>
>
>OR
>
>$master_names[0]="Joe"
>$master_names[1]="Sam"
>$master_names[2]="Tom"
>
>becomes...
>
>$master_names['master_names0']="Joe"
>$master_names['master_names1']="Sam"
>$master_names['master_names2']="Tom"
>
>
>Yes, that is it.
>
>Warmest regards,
>
>Peter Sawczynec
>Technology Director
>PSWebcode
>_Design & Interface
>_Ecommerce
>_Database Management
>646.316.3678
><mailto:ps at pswebcode.com>ps at pswebcode.com
>www.pswebcode.com
>
>_______________________________________________
>New York PHP Community Talk Mailing List
>http://lists.nyphp.org/mailman/listinfo/talk
>
>NYPHPCon 2006 Presentations Online
>http://www.nyphpcon.com
>
>Show Your Participation in New York PHP
>http://www.nyphp.org/show_participation.php




More information about the talk mailing list