hilda Posted January 6, 2013 Share Posted January 6, 2013 Hello everyone I've got a salary.txt as follow: 500001700065003500022100456609000 And the php code with follow:<?$salary = file("salary.txt");echo max($salary);echo min($salary);?> But the output is: 900017000 Any ideas? Thanks! Link to comment Share on other sites More sharing options...
boen_robot Posted January 6, 2013 Share Posted January 6, 2013 The output from file() are strings of lines, not integers. The rules for comparing strings are different.You need to go over the lines, and convert the strings to numbers before you check them, e.g. <?php$salary = file('salary.txt');for($i=0, $c=count($salary); $i<$c; ++$i) { $salary[$i] = (int) $salary[$i];}//OK, now it's all integersecho max($salary);echo min($salary); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now