Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

How to loop through this kind of an array returned from mailchimp.

Hi,
Using the mailchimp API I'm returning the array below. It contains the email addresses and their open counts for a particular email campaign. I'm having a hard time trying to loop through it so I can insert each email and corresponding open count into my db. Can someone show me an example of looping through this thing to do an insert?

array(2) { [0]=> array(2) { ["email"]=> string(24) "john@mysite.com" ["open_count"]=> int(1) } [1]=> array(2) { ["email"]=> string(23) "bill@mydomain.com" ["open_count"]=> int(3) } } 

Open in new window


Thanks as always,
tj
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This appears to be an array of arrays.  Iterate over the top array to get each "sub-array" by number.  Iterate over each "sub-array" to get the elements named "email" and "open_count".

array(2) 
{ [0]=> array(2) 
  {  ["email"]=> string(24) "john@mysite.com" 
     ["open_count"]=> int(1)
  } 
  [1]=> array(2) 
  {   ["email"]=> string(23) "bill@mydomain.com" 
      ["open_count"]=> int(3) 
  }
} 

Open in new window

Avatar of tjyoung
tjyoung

ASKER

Hi,
I've tried hundred variations only getting stuff like: arrayarray and a myriad of other mistakes. I'd post my attempts but none of them seemed close or simply failed.

cleaning up the arrays I appreciate, should've done that posting my question.

Can you give me an example of iterating through this? I can figure out adding to a DB I should think but I can't for the life of me get to the correct data.

Its a bit of a grey area in my 'home schooling' efforts.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjyoung

ASKER

Thank you very much. Makes perfect sense once you see it...