Jump to content

killemall

New Members
  • Posts

    2
  • Joined

  • Last visited

killemall's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, that was the problem
  2. i have a problem with a script, the script read a file (csv) and stores the last value of each line in an array, then i calculate the maximun,minimun and average of the values in the array, but with big files the script give me an incorrect value for the maximun,minimun and average, with the file 8.csv the calculations are correct but with the file 1.csv the values are wrong, the only difference i see is that the file 1.csv is much larger than the other. Thanks for your help!!! This is the code: <?php $variable2=file("1.csv"); $i=0; foreach($variable2 as $var){ if($i==0){ $i++; }else{ $datos=explode(",",$var); $valor=$datos[count($datos)-1]; if($valor!= -3000){ $todos[$i-1]=$valor; $i++; } } } $promedio=array_sum($todos) / count($todos); $maximo=max($todos); $minimo=min($todos); echo "MAXIMO = ".$maximo." MINIMO = ".$minimo." PROMEDIO = ".$promedio; ?> And this is a part of the file 1.csv (the full file have more than 60.000 lines) OBJECTID,pointid,grid_code,potrero_ID,MOD13Q1.A2 7300.0,7300.0,1.0,1,6431 7498.0,7498.0,1.0,1,6684 7499.0,7499.0,1.0,1,6431 7500.0,7500.0,1.0,1,6431 7501.0,7501.0,1.0,1,6431 7502.0,7502.0,1.0,1,6431 7503.0,7503.0,1.0,1,6431 7504.0,7504.0,1.0,1,6304 7697.0,7697.0,1.0,1,6734 7698.0,7698.0,1.0,1,6734 7699.0,7699.0,1.0,1,6127 7700.0,7700.0,1.0,1,6127 Expected values: Maximun: 9307 Minimun: -650 Average: 6555,211347 Output values: Maximun: 999 Minimun: -104 Average: 6555,3296310272 If you want you can download the code and input files here: https://www.dropbox.com/s/y4vpjm6086rj3s3/script.zip Thanks.
×
×
  • 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.