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 Link to comment https://forums.phpfreaks.com/topic/276917-sort-and-join-in-group-in-array/ 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 Link to comment https://forums.phpfreaks.com/topic/276917-sort-and-join-in-group-in-array/#findComment-1424616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.