Jump to content

Problem with min() and max()


hilda

Recommended Posts

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! :umnik2:

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...