Array String Offset Checker

Set this once in the functions file


$people_meta_keys[] = 'title';
$people_meta_keys[] = 'role';
$people_meta_keys[] = 'pdf';
$people_meta_keys[] = 'phone';
$people_meta_keys[] = 'fax';
$people_meta_keys[] = 'phone';
$people_meta_keys[] = 'office_id';


update_option('people_meta_keys',$people_meta_keys);

Then paste this permanently in the general functions file


function offset_checker($the_array, $the_group) {

	$group_keys = get_option($the_group);

    if (empty($the_array)) { $the_array = array(); }
    
    
    foreach($group_keys as $this_key) {
		if (!array_key_exists($this_key, $the_array)) {
		    $the_array[$this_key] = "";
		}  
    }
    
    return $the_array;
    
}  

Then call it like this


$whatever_array =  offset_checker($whatever_array,'whatever_keys')

Comments