raymond_feliciano Posted May 19, 2012 Share Posted May 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262792-consolidating-a-multilevel-array/ Share on other sites More sharing options...
Barand Posted May 19, 2012 Share Posted May 19, 2012 Why don't you create the array using the account number as the key? You then remove the need to consolidate. Quote Link to comment https://forums.phpfreaks.com/topic/262792-consolidating-a-multilevel-array/#findComment-1346913 Share on other sites More sharing options...
raymond_feliciano Posted May 20, 2012 Author Share Posted May 20, 2012 @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 Quote Link to comment https://forums.phpfreaks.com/topic/262792-consolidating-a-multilevel-array/#findComment-1347025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.