jadeg Posted March 10, 2014 Share Posted March 10, 2014 I have a csv file and I am trying to get the minimum value for a particular column. However I am not getting an exact value even after exploding the values. After I explode and I do a var_dump on it, it produces a different array for each different row; so each value in the column is the first element of a different array. How do I merge this different arrays into one array in order to find the minimum value in the column, or is there any other way to go about it? Below is my code. Any help will be appreciated. My code is below and a link to the excel file https://www.dropbox.com/s/n7pyv96qv1yv8yc/Example%20SG%20Data.xlsxwhile (($data = fgetcsv($handle, 0, ",")) !== false) { $table2Add =false;if($row >=$x && $row <=$y) {$table2Add=true; }if($row == 1) {$table2 .= '<thead><tr>';$table2 .= '<th></th>';$table2 .= '<th>Min</th>';$table2 .= '<th>Max</th>';$table2 .= '<th>Average</th>';$table2 .= '</tr></thead><tbody>';}else {if($table2Add) $table2 .= '<tr><th>Voltage</th>';for($c = 0; $c <= 10; $c++) {$value = empty($data[$c]) ? " " : $data[$c];if($c==1) {var_dump((explode('STRING',$data[$c])));//$ar=explode('STRING', $data[$c]);//var_dump(min($ar));if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';} if($c==2) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}if($c==3) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}}if($table2Add) $table2 .= '</tr>';if($table2Add) $table2 .= '<tr><th>Current</th>';for($c = 0; $c <= 10; $c++) {$value = empty($data[$c]) ? " " : $data[$c];if($c==4) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}if($c==5) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}if($c==6) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}}if($table2Add) $table2 .= '</tr>';if($table2Add) $table2 .= '<tr><th>Power Factor</th>';for($c = 0; $c <= 10; $c++) {$value = empty($data[$c]) ? " " : $data[$c];if($c==7) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}if($c==8) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}if($c==9) {if ($table2Add) $table2 .='<td>'.round($value,2).'</td>';}}if($table2Add) $table2 .= '</tr>';}$row++;} Quote Link to comment Share on other sites More sharing options...
mogosselin Posted March 10, 2014 Share Posted March 10, 2014 It would be easier to check your code if you use the "code" button and indent your code. Also, you should check out the str_getcsv() method: http://www.php.net/manual/en/function.str-getcsv.php I never used it but it seems done for what you want to do. Quote Link to comment Share on other sites More sharing options...
jadeg Posted March 10, 2014 Author Share Posted March 10, 2014 Will try it out. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.