SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Divisive Cotton's Avatar
    Join Date
    Jun 2008
    Location
    Andy lives in London, UK
    Posts
    393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically changing array keys

    I'm importing a number of files and I need to standardise the array keys. As the rest are numbered then I need to change the array keys to numbers for those that have alternative names

    I'm getting close, but not there

    This is what the array looks like:

    PHP Code:
    array
      
    'program_id' => string '1503' (length=4)
      
    'program_name' => string 'Baby Curls' (length=10)
      
    'product_id' => string '100' (length=3)
      
    'product_name' => string 'Wheelybug - Mouse' (length=17)
      
    'description' => string 'Wheelybugs are designed to offer hours of robust fun and help to promote self-confidence, spatial awareness and gross motor skills.
    Special features:

    Bodies have a padded layer of sponge covered with tough polyurethane 
    Easily wiped clean 
    For use on all level surfaces 
    Handmade and beautifully crafted from the highest quality materials 
    Multi-directional castors 
    Unlimited mobility 
    Small: 36cm long x 23cm high x 20cm wide (Age: 1 - 2.5 years) 
    Large: 46cm long x 28cm high x 26cm wide (Age: 2.5 andndash; '
    ... (length=520)
      
    'deeplink' => string 'http://track.webgains.com/click.html?wgcampaignid=88263&wgprogramid=1503&product=1&wglinkid=89549&productname=Wheelybug+-+Mouse&wgtarget=http://www.babycurls.co.uk/baby-products/wheelybugs-/wheelybug-mouse/' (length=206)
      
    'price' => string '46.01' (length=5)
      
    'image_url' => string 'http://www.babycurls.co.uk/images/products_image1-100.jpg' (length=57)
      
    'category_id' => string '2209' (length=4)
      
    'category_name' => string 'Walkers' (length=7)
      
    'category_path' => string 'Baby Toys > Walkers' (length=19)
      
    'merchant_category' => string 'Wheelybugs' (length=10)
      
    'last_updated' => string '2012-02-09 22:14:47' (length=19)
      
    'currency' => string 'GBP' (length=3)
      
    'delivery_cost' => string '0.00' (length=4)
      
    'delivery_period' => string 'Free Delivery 3-5 Days (Royal Mail)' (length=35)
      
    'image_large_url' => string 'http://www.babycurls.co.uk/images/products_image1-100.jpg' (length=57)
      
    'image_thumbnail_url' => string 'http://www.babycurls.co.uk/images/products_image1-100.jpg' (length=57)
      
    'language' => string '' (length=0)
      
    'Full_merchant_price' => string '46.01' (length=5)
      
    'short_description' => string 'Wheelybugs are designed to offer hours of robust fun and help to promote self-confidence, spatial aw' (length=100
    Using the following code:

    PHP Code:
     foreach ($array as $result) {

                    foreach (
    $result as $key => $value) {
                        static 
    $i 0;
                        
    $i++;
                       
                        echo 
    $i ': ' $value br;

                    }

                } 
    Prints out the following:

    Code:
    1: 1503
    2: Baby Curls
    3: 100
    4: Wheelybug - Mouse
    5: Wheelybugs are designed to offer hours of robust fun and help to promote self-confidence, spatial awareness and gross motor skills. Special features: Bodies have a padded layer of sponge covered with tough polyurethane Easily wiped clean For use on all level surfaces Handmade and beautifully crafted from the highest quality materials Multi-directional castors Unlimited mobility Small: 36cm long x 23cm high x 20cm wide (Age: 1 - 2.5 years) Large: 46cm long x 28cm high x 26cm wide (Age: 2.5 andndash; 5 years)
    6: http://track.webgains.com/click.html?wgcampaignid=88263&wgprogramid=1503&product=1&wglinkid=89549&productname=Wheelybug+-+Mouse&wgtarget=http://www.babycurls.co.uk/baby-products/wheelybugs-/wheelybug-mouse/
    7: 46.01
    8: http://www.babycurls.co.uk/images/products_image1-100.jpg
    9: 2209
    10: Walkers
    11: Baby Toys > Walkers
    12: Wheelybugs
    13: 2012-02-09 22:14:47
    14: GBP
    15: 0.00
    16: Free Delivery 3-5 Days (Royal Mail)
    17: http://www.babycurls.co.uk/images/products_image1-100.jpg
    18: http://www.babycurls.co.uk/images/products_image1-100.jpg
    19:
    20: 46.01
    21: Wheelybugs are designed to offer hours of robust fun and help to promote self-confidence, spatial aw
    I'm sure it can't be much further to go now
    Let everyday be Christmas

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    So... you want to take an Associative array, and make it into a Numeric array?
    $array = array_values($array);

    done.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •