Created
July 16, 2010 18:08
-
-
Save devrim/478699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a good idea. This is easy to add if you have a model that supports a beforeSave() event...