douzhang3356 2014-02-20 19:39
浏览 35

将数组合并到单个数组以查找最小值

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.

merging

while (($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]) ? "&nbsp;" : $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]) ? "&nbsp;" : $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]) ? "&nbsp;" : $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++;
        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表