views:

36

answers:

1

Hello I have a text file with three lines. every line has a float number. How can I take each value and put in a float variable even if array?

For example text file is like the following

+3.01\n
-0.0012\n
-0.1\n

I want an array [if it possible] which save the values as float not as string.

Thanks

+3  A: 
$fileArr = file($fileName);
$fileArr = array_map('floatval', $fileArr);
Jhong
could make it a one-liner `$fileArr = array_map('floatval', file($fileName));`
Gordon