michal011 Posted April 13, 2013 Share Posted April 13, 2013 Hopefully, I can explain this correctly...I have a multidimensional array and am trying to group them according to the value of one the keys. input table: Array ( [0] => Array ( [0] => Kiynf [1] => sort1 [2] => extraPar1 ) [1] => Array ( [0] => Lwbyg [1] => sort1 [2] => extraPar1 ) [2] => Array ( [0] => HOUpe [1] => sort2 [2] => extraPar1 ) [3] => Array ( [0] => iSPtD [1] => sort2 [2] => extraPar1 ) [4] => Array ( [0] => NVXkO [1] => sort2 [2] => extraPar1 ) [5] => Array ( [0] => uRZFv [1] => sort2 [2] => extraPar1 ) [6] => Array ( [0] => ZLGMo [1] => sort2 [2] => extraPar1 ) [7] => Array ( [0] => 5dEQl [1] => sort3 [2] => extraPar1 ) [8] => Array ( [0] => lnEeg [1] => sort3 [2] => extraPar1 ) [9] => Array ( [0] => AO5Eo [1] => sort3 [2] => extraPar1 ) ... ) and i want to, get array like this: Array ( [0] => Array ( [group] => Kiynf | Lwbyg [1] => sort1 [2] => extraPar1 ) [2] => Array ( [group] => HOUpe | iSPtD | NVXkO | uRZFv | ZLGMo [1] => sort2 [2] => extraPar1 ) [3] => Array ( [group] => 5dEQl | lnEeg | AO5Eo [1] => sort3 [2] => extraPar1 ) ... pls help Quote Link to comment Share on other sites More sharing options...
Barand Posted April 13, 2013 Share Posted April 13, 2013 try $result = $temp = array(); foreach ($arr as $a) { $temp[$a[1].'|'.$a[2]][] = $a[0]; } foreach ($temp as $k=>$b) { $result[] = array_merge ( array(join(' | ', $b)), explode('|', $k) ); } resut is in $result Quote Link to comment 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.