Jump to content

consolidating a multilevel array


Recommended Posts

I have an array which can contain nth number of arrays. These arrays contain data from a query joining three tables and a where clause

 

array
  0 => 
    array
      'account_num' => string '1' (length=1)
      'icd9_code' => string '1' (length=1)
      'dob' => string '12-12-1955' (length=10)
      'sex' => string 'Male' (length=4)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 1' (length=
  1 => 
    array
      'account_num' => string '1' (length=1)
      'icd9_code' => string '1' (length=1)
      'dob' => string '12-12-1955' (length=10)
      'sex' => string 'Male' (length=4)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 2' (length=
  2 => 
    array
      'account_num' => string '1' (length=1)
      'icd9_code' => string '1' (length=1)
      'dob' => string '12-12-1955' (length=10)
      'sex' => string 'Male' (length=4)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 3' (length=
  3 => 
    array
      'account_num' => string '1' (length=1)
      'icd9_code' => string '1' (length=1)
      'dob' => string '12-12-1955' (length=10)
      'sex' => string 'Male' (length=4)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 4' (length=
  4 => 
    array
      'account_num' => string '2' (length=1)
      'icd9_code' => string '2' (length=1)
      'dob' => string '11-11-1958' (length=10)
      'sex' => string 'Female' (length=6)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 1' (length=
  5 => 
    array
      'account_num' => string '2' (length=1)
      'icd9_code' => string '2' (length=1)
      'dob' => string '11-11-1958' (length=10)
      'sex' => string 'Female' (length=6)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 3' (length=
  6 => 
    array
      'account_num' => string '2' (length=1)
      'icd9_code' => string '2' (length=1)
      'dob' => string '11-11-1958' (length=10)
      'sex' => string 'Female' (length=6)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 4' (length=
  7 => 
    array
      'account_num' => string '3' (length=1)
      'icd9_code' => string '3' (length=1)
      'dob' => string '03-11-1958' (length=10)
      'sex' => string 'Female' (length=6)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 3' (length=
  8 => 
    array
      'account_num' => string '3' (length=1)
      'icd9_code' => string '3' (length=1)
      'dob' => string '03-11-1958' (length=10)
      'sex' => string 'Female' (length=6)
      'study' => string 'study 2' (length=7)
      'prescription' => string 'script 4' (length=

 

As you can see most of the information is repeated. How would I loop thru each array and consolidate the data so i could output it as follows

 

account num 1

icd9 code 1

dob 12-12-1955

sex Male

study study 2

prescriptions script 1, script 2, script 3, script 4

 

account num 2

icd9 code 2

dob 11-11-1958Femsex Male

study study 2

prescriptions script 1, script 3, script 4

 

and so on.

 

I tried using array_unique but all I cant figure out how to consolidate the data.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.