Replace array key with new array key.

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.

[php]
/*
* 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
[/php]

This entry was posted in Computers.

Post a Comment

You must be logged in to post a comment.