I am fetching an array of floats from my database but the array I get has converted the values to strings.
How can I convert them into floats again without looping through the array?
Alternatively, how can I fetch the values from the database without converting them to strings?
EDIT:
-
I am using the Zend Framework and I am using PDO_mysql. The values are stored one per column and that is a requirement so I can’t serialize them.
-
array_map('floatval', $array)only works on single dimensional arrays. -
I can’t
floatvalthe single elements when I use them because I have to pass an array to my flash chart. -
The momentary, non-generic solution is to extract the rows and do
array_map('floatval',$array)with each row.
You could use
There is the option
PDO::ATTR_STRINGIFY_FETCHESbut from what I remember, MySQL always has it astrueEdit: see Bug 44341 which confirms MySQL doesn’t support turning off stringify.
Edit: you can also map a custom function like this: