Sotiris
Sotiris

Reputation: 40096

php read from file float

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

Upvotes: 0

Views: 698

Answers (1)

Jhong
Jhong

Reputation: 2752

$fileArr = file($fileName);
$fileArr = array_map('floatval', $fileArr);

Upvotes: 5

Related Questions