what i need
- I Need to group array of same type.
- like
array1 ['type']=a
andarray2 ['type']=a
then it should be grouped in single array.
array structure
Array
(
[1] => Array
(
[type] => ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular
[amount] => 850
[comment] => On or Before June 28, 2014
)
[2] => Array
(
[type] => ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Friend
[amount] => 1000
[comment] => On or Before June 28, 2014
)
[3] => Array
(
[type] => ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Student
[amount] => 500
[comment] => On or Before June 28, 2014
)
[4] => Array
(
[type] => ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular)
[amount] => 990
[comment] => June 29 thru July 20, 2014
)
PHP Code
foreach($data as $k=>$v){
$type[$v['type']][]=$k;
}
//loop types, creating result array
foreach($type as $k=>$v){
$tmp=array(
'type'=>$kk,
'metadata'=>array()
);
//loop all the arrays of this type
foreach($v as $w){
//store in TMP
$t=array(
'amount' => $data[$w]['amount'],
'comment' => $data[$w]['comment']
);
//store
$tmp['metadata'][]=$t;
}
$result[]=$tmp;
}
output of type
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular] => Array
(
[0] => 1
[1] => 7
)
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Friend] => Array
(
[0] => 2
[1] => 5
[2] => 8
)
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Student] => Array
(
[0] => 3
[1] => 6
[2] => 9
)
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular)] => Array
(
[0] => 4
)
Problem im getting
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular] => Array
(
[0] => 1
[1] => 7
)
[ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular)] => Array
(
[0] => 4
)
this array having same type but is not grouped.
i want ECOOP Conference, Workshops and UPMARC Summer School (Mon-Fri July 28 - August 1) Regular to grouped in single array .
how to tackle this problem any suggestion are most welcome.