www.webdeveloper.com
Results 1 to 1 of 1

Thread: Multi-dimensional arrays in a foreach loop?

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264

    Exclamation Multi-dimensional arrays in a foreach loop?

    Ok, so I'm not used to using the foreach loop, so tell me if this is (in theory) getting too complicated to work...

    First, I have a function that gets all of the info I need from my database, it returns an array sort of like this:
    PHP Code:
    $myrow[0]['id'] = '165';
    $myrow[0]['name'] = 'Sally';
    $myrow[0]['age'] = '23';
    $myrow[0]['status'] = 'Employed'
    Ok, so then I use this to try and process the data: ... sort of.
    PHP Code:
        foreach(pullData('SELECT from myDB WHERE name = Sally') as $value){
            list(
    'id','name','age','status') = $value;
            
    // Do whatever you were going to do with the data... code goes here.
        

    My intent is to grab each row as I go in the easiest way possible (without having to re-type the "get data from the database" stuff each time I need to use it, just a quick "pullData($query)" function to grab everything... and then use it one line at a time after it gets stored in the list...
    Last edited by amandaNHT; 11-29-2012 at 01:05 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles