I have an array :
$stu_result( [exam_type] => 1 [subject_id] => 5 [converted_mark] =>5.00[student_id] => 186 [sub_name] => maths)
and its length is 15.
I want to match exam type and store sub_name and converted marks in a blank array. I tried this code :
This is my code tried so far
$result_exam1 = array();
foreach($stu_result as $result_temp){
if($result_temp['exam_type'] == 1){
$result_exam1['converted_mark'] = $result_temp['converted_mark'];
$result_exam1['sub_name'] = $result_temp['sub_name'];
}
}
Hope this will help you :
Note : $stu_result
should be a multidimensional array to loop and use key value
feature of foreach loop to get all data like this :
$result_exam1 = array();
foreach($stu_result as $key => $result_temp)
{
if($result_temp['exam_type'] == 1)
{
$result_exam1[$key]['converted_mark'] = $result_temp['converted_mark'];
$result_exam1[$key]['sub_name'] = $result_temp['sub_name'];
}
}
print_r($result_exam1);