sandy1028 Posted July 27, 2007 Share Posted July 27, 2007 Hi, I want to find the maximum and minimum, average value from the text file <? $lines = file('./data.txt'); foreach ($lines as $line) { $text_line = explode(":" , $line); $text_line1 = explode(" " , $text_line[2]); array_sum($text_line1); } ?> This method I am not able to get the array sum..... How to get the numerical value of numbers from strings When I explode the line it is in string format.... I should find the array_sum and max() which I values are in numeric not string Link to comment https://forums.phpfreaks.com/topic/62001-maximum-and-minimum-value/ Share on other sites More sharing options...
sandy1028 Posted July 27, 2007 Author Share Posted July 27, 2007 Hi, I am facing problem here not able to fetch the exact values of averag and sum It is fetching the last value I should pass the value of avg and maximum in to array $graphValues=array($avg,$max); <?php $lines = file('./phonedb.txt'); $count= count($lines); foreach ($lines as $line) { $arrLineValues = explode(":" , $line); $arrField2Values = explode(" " , $arrLineValues[2]); $max = max($arrField2Values); $sum = array_sum($arrField2Values); $avg = $sum/$count; } ?> Link to comment https://forums.phpfreaks.com/topic/62001-maximum-and-minimum-value/#findComment-308741 Share on other sites More sharing options...
hvle Posted July 27, 2007 Share Posted July 27, 2007 try this <?php $lines = file('./phonedb.txt'); $count= count($lines); //added $allNumbers = array(); foreach ($lines as $line) { $arrLineValues = explode(":" , $line); $arrField2Values = explode(" " , $arrLineValues[2]); $allNumbers = array_merge($allNumbers, $arrField2Values); } $max = max($allNumbers); $sum = array_sum($allNumbers); $avg = $sum/count($allNumbers); ?> Link to comment https://forums.phpfreaks.com/topic/62001-maximum-and-minimum-value/#findComment-308748 Share on other sites More sharing options...
sandy1028 Posted July 27, 2007 Author Share Posted July 27, 2007 Hey thanks it is working Link to comment https://forums.phpfreaks.com/topic/62001-maximum-and-minimum-value/#findComment-308781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.