Your very first code shows you have to get an understanding of just what it is you are doing - if this is the form target then what is the source of $post?
If it's supposed to be the form it would be $_POST and it would NOT be an array:
foreach ($post['exam_passed'] as $id => $slno) {
if (empty($exam_passed_)) {
$error[] = 'exam_passed_' . $id;
$error_message[] = 'exam_passed_ can not be blank.';
}
}
You have a foreach loop for $post (from whatever source you get it from) would thus be an array operation on a value that is not an array, but a member of one.
It's typically a better idea to validate on the client side (unless data needs to be checked on the server) - which is done with javaScript.
It just seems to big a mess to fix until you get it all in some logical order.