PHP中的Max函数在字符串上失败?

Given this list.txt file:

9
10
19

Guess what?

max(split(" ",$file_handle)) gives me 9

max(explode(PHP_EOL,$file_handle)) gives me 9

Now, on a string:

$string = "9 10 19"; max(split(" ",$string)) gives me 19

Updated: When reading from a file, I get strings and max() can't seems to find the correct max when comparing string values?! 9 is bigger than 10. The same file content on a string works fine. file_get_contents()/fread() same issue.

Are you sure that EOL (end-of line) is " "?

Look at this answer:

Explode PHP string by new line

And check this for EOL explanation:

Difference between and ?

This solves it. Still a mystery to me why values come as string from file and as numbers from a string with the same content. Anyway, here's the fix:

max(array_map('intval', split("
",$file_handle)));