Jump to content
Sign in to follow this  
hilda

Problem with min() and max()

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:

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...