Replace array key with new array key.

| December 10, 2009 | Reply

I found that in my model, if the table columns were not explicity set, I ran into problems. This is the block of code I used to check an options array, and replace any non explicit table columns with explicit ones.

/*
* This block will take any option keys that do not have a table
* explicitly set, and will append the given table to them.
*/
$keywords=array(‘limit’,’offset’,’sortBy’,’sortDirection’,’joins’);
foreach ($options as $key=>$value){
if (!in_array($key,$keywords)){
if (!preg_match (‘/[^a-z]/i’, $key)) {
$options[$table.'.'.$key]=$options[$key];
unset($options[$key]);
}//end if
}//end if
}//end foreach

Tags:

Category: Uncategorized

About the Author ()