Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* use this function before inserting any array to mongo */
array_walk_recursive($array,"typeCast");
/* then do insert: $mongo->$db->$collection_name->insert($array); */
/* careful with & sign before the $item, dont remove it, */
function typeCast(&$item,$key){
if(is_numeric($item)) $item = (float) $item;
else $item = (string) $item;
}
@mgirouard

This comment has been minimized.

Copy link

commented Oct 15, 2010

This is a good idea. This is easy to add if you have a model that supports a beforeSave() event...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.