General_Twyckenham
General_Twyckenham

Reputation: 2261

PHP use file() but read lines as integers

It seems like a pretty simple issue and one that I thought for sure would have been asked before but I've been searching for some time now and have not found a solution.

When using PHP's file() command, it reads the file and puts each line in an array as a String. Is there any way to read each line as an integer?

(I know that I could just through the array and convert it to an int, but I figure that will slow it down somewhat)

Upvotes: 1

Views: 40

Answers (1)

Amal Murali
Amal Murali

Reputation: 76636

Nope. The only way is to do it manually. Fortunately, that's easy:

$lines = array_map('intval', file($path));

Upvotes: 1

Related Questions