I have two array one for present list and other for total lectures. i want a third array that will hold the percent of two
My first array (present days list)
$allpresentAttInfo = array(
0 => array(
'year' => '2013',
'term' => 'T1',
'presentDays' => '123'
),
1 => array(
'year' => '2013',
'term' => 'T2',
'presentDays' => '112'
)
);
My Second array (Total days list)
$allAttInfo = array(
0 => array(
'year' => '2013',
'term' => 'T1',
'totalDays' => '200'
),
1 => array(
'year' => '2013',
'term' => 'T2',
'totalDays' => '216'
)
);
My Resultant array should be like this
$attInfo = array(
0 => array(
'year' => '2013',
'term' => 'T1',
'presentPercent' => '63.7 %'
),
1 => array(
'year' => '2013',
'term' => 'T2',
'presentPercent' => '42.7 %'
)
);
So by merging both the arrays i will have to find the present present in given year and term. How to achieve this on PHP side. Thanks in advance
Well thanks guys .. I was in a hurry so searching for some short-cut copy paste way ... Well i coded it. but still give me some performance optimization if available.
My Solution is.
$attInfo = array();
foreach ($allAttInfo as $allatt) {
foreach ($allpresentAttInfo as $allpre) {
if($allpre['year'] == $allatt['year'] && $allpre['term'] == $allatt['term']){
$presentPercent = round(($allpre['presentDays'] / $allatt['totalDay'])*100,2) . "%";
$newArray=array('year'=>$allpre['year'],'term'=>$allpre['term'],'presentPercent'=>$presentPercent);
array_push($attInfo, $newArray);
}
}
}