Jump to content

To find the number


sandy1028

Recommended Posts

Hi,

 

How to find the maximum value from the file.

 

$lines = file('data.txt');
       foreach ($lines as $line) {
       $text_line = explode(":",$line);

In $text_line[2] i should find the maximum value and average value....
using max($text_line[2]) I am getting error

Link to comment
Share on other sites

How to find the large number when read from the text file.

 

In the file the $text_line[2] is the numerical values.

How to find the largest number

 

When I print the $text_line[2]

output is 32  23  23  34  23  56  23  222  123  67

 

To sort as array and find the maximum value this is not the array

 

Any help regarding this to find the large number

 

Link to comment
Share on other sites

as what u said earlier ... it seems $text_line[2] is a string of 32  23  23  34  23  56  23  222  123  67 ........ is it ....

so make it a array

like

$aTest = explode(' ',  $text_line[2]);

 

// to get max value

  max($aTest);

 

// to get average ...

  array_sum($aTest)/count($aTest);

 

hope this is wht u want ......

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.