«

»

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.

/*
* 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

Permanent link to this article: http://www.lukemacneil.com/2009/12/10/replace-array-key-with-new-array-key/

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>