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
https://forums.phpfreaks.com/topic/262792-consolidating-a-multilevel-array/
Share on other sites

@Barand thanks for the suggestion but I was unable to make the original array from the account number as the key because I am using codeigniters software and their database model returns the data in this manner.

 

I was able to figure out the issue I was having. Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.