NYCPHP Meetup

NYPHP.org

[nycphp-talk] Array Transformation Assistance.

Peter Sawczynec ps at pswebcode.com
Mon Oct 2 15:37:26 EDT 2006


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:
 
$Any_Variable_Name = array('joe', 'adam', 'alex');
$master_new   = array( );
 
while(list($index, $value) = each($Any_Variable_Name))
{
    $master_new[$Any_Variable_Name. $index] = $value;
}

 
Thank you.
Peter

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of Ben Sgro (sk)
Sent: Monday, October 02, 2006 3:10 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Array Transformation Assistance.


<?php
 
$master_names = array('joe', 'adam', 'alex');
$master_new   = array( );
 
while(list($index, $value) = each($master_names))
{
    $master_new['master_names' . $index] = $value;
}
print_r($master_new);
 
?>

----- Original Message ----- 
From: Peter Sawczynec <mailto:ps at pswebcode.com>  
To: 'Org, Talk at Nyphp.' <mailto:Talk at Nyphp.'>  
Sent: Monday, October 02, 2006 3:04 PM
Subject: [nycphp-talk] Array Transformation Assistance.

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 
ps at pswebcode.com 
www.pswebcode.com <http://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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061002/b831b551/attachment.html>


More information about the talk mailing list