SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)

    Replacing the first array key, easier way?

    Is there an easier way of achieving this:
    PHP Code:
    $d[$_id]['org_name']  = $d['Partner']['org_name'] ;
    $d[$_id]['tel']       = $d['Partner']['tel'] ;
    .. 
    etc 
    Its essentially the same array, but the key needs to be replaced.

    Imagine its part of a loop of 'Partners' which need to be brought into a single multi-array, and has x number of entries, it just hurts my eyes to look at lines like that - and it makes it makes my code horribly brittle.

    Any ideas?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this what you mean?
    PHP Code:
    $d[$_id] = $d['Partner']; 
    Optionally followed by unset(). Or just use a new variable instead of $d for the assignment.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    That simple re-assignment worked, and did not affect the multi arrays below it.

    Thank you in big blue letters too

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Thank you in big blue letters too
    lol


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •