NYCPHP Meetup

NYPHP.org

[nycphp-talk] Array Transformation Assistance.

Ben Sgro (sk) skyline at publicmine.com
Mon Oct 2 15:10:23 EDT 2006


Message<?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 
  To: 'Org, 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 



------------------------------------------------------------------------------


  _______________________________________________
  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/a08d7518/attachment.html>


More information about the talk mailing list