Skip to content

Instantly share code, notes, and snippets.

@devrim
Created July 16, 2010 18:08
Show Gist options
  • Save devrim/478699 to your computer and use it in GitHub Desktop.
Save devrim/478699 to your computer and use it in GitHub Desktop.
/* 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
Copy link

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