<?php
$function_codes_array_const = array(
    array('name' => 'Create User', 'code' => 'create_user', 'allowed_roles' => array('superadmin','admin')),
    array('name' => 'Alter User', 'code' => 'alter_user', 'allowed_roles' => array('superadmin','admin')),
    
    array('name' => 'Create Academic Session', 'code' => 'create_session', 'allowed_roles' => array('superadmin','admin')),
    array('name' => 'Alter Academic Session', 'code' => 'alter_session', 'allowed_roles' => array('superadmin','admin')),
    
    array('name' => 'Create Class', 'code' => 'create_class', 'allowed_roles' => array('superadmin','admin')),
    array('name' => 'Alter Class', 'code' => 'alter_class', 'allowed_roles' => array('superadmin','admin')),
    
    array('name' => 'Create Section', 'code' => 'create_section', 'allowed_roles' => array('superadmin','admin','principal')),
    array('name' => 'Alter Section', 'code' => 'alter_section', 'allowed_roles' => array('superadmin','admin','principal')),
    
    array('name' => 'Create Subject', 'code' => 'create_subject', 'allowed_roles' => array('superadmin','admin','principal')),
      array('name' => 'Alter Subject', 'code' => 'alter_subject', 'allowed_roles' => array('superadmin','admin','principal')),
  
    array('name' => 'Create Timetable', 'code' => 'create_timetable', 'allowed_roles' => array('superadmin','admin','principal')),
    array('name' => 'Alter Timetable', 'code' => 'alter_timetable', 'allowed_roles' => array('superadmin','admin','principal')),
    
    array('name' => 'Create Homework', 'code' => 'create_homework', 'allowed_roles' => array('teacher')),
    array('name' => 'Alter Homework', 'code' => 'alter_homework', 'allowed_roles' => array('teacher')),
);

function verify_user_allowed_functioncode($role, $code) {
    // write a code that first iterates through function codes array const
    // when it iterates over it check that the code == code, then check if $role is present in allowed_roles of that element
    // return true or false;
    
    foreach($GLOBALS['function_codes_array_const'] as $element) {
            if($element['code'] == $code) {
                
             if($element['allowed_roles'] == $role){
                
                return true;
               
            }else{
                return false;
            }
            
        }
    }
    
}

?>