提高PHP执行速度

时间:2017-04-26 14:17:59

标签: php

请问如何提高php代码的速度。我有超过1580行代码需要处理大约103,000个数据集。目前,此代码处理1个数据集需要5分钟以上。它包含30个for循环和168个条件语句。

$tnu =0; $tcp=0; $tnup = 0;         
                if($SsNoCourses[$sessionCounter] != 0){
                    //echo $SsNoCourses[$sessionCounter]."</br>";
                    $secondSemesterExist = "True";
                    $actualSemesterCounter = $actualSemesterCounter + 1;
                    $lastComputedSemesterId = $actualSemesterCounter;

                    for($i = 0; $i<$noOfCoursesS; $i++){
                        if ($sessionCounter == 1){
                                $tnu = $tnu + $SsY1Courses[$i][2];
                                $tcp = $tcp + $SsY1Courses[$i][2]*$SsY1Courses[$i][4];          
                                if ($SsY1Courses[$i][4] != 0){$tnup = $tnup + $SsY1Courses[$i][2];}
                            }else if ($sessionCounter == 2){
                                $tnu = $tnu + $SsY2Courses[$i][2];
                                $tcp = $tcp + $SsY2Courses[$i][2]*$SsY2Courses[$i][4];          
                                if ($SsY2Courses[$i][4] != 0){$tnup = $tnup + $SsY2Courses[$i][2];}
                            }else if ($sessionCounter == 3){
                                $tnu = $tnu + $SsY3Courses[$i][2];
                                $tcp = $tcp + $SsY3Courses[$i][2]*$SsY3Courses[$i][4];          
                                if ($SsY3Courses[$i][4] != 0){$tnup = $tnup + $SsY3Courses[$i][2];}
                            }else if ($sessionCounter == 4){
                                $tnu = $tnu + $SsY4Courses[$i][2];
                                $tcp = $tcp + $SsY4Courses[$i][2]*$SsY4Courses[$i][4];          
                                if ($SsY4Courses[$i][4] != 0){$tnup = $tnup + $SsY4Courses[$i][2];}
                            }else if ($sessionCounter == 5){
                                $tnu = $tnu + $SsY5Courses[$i][2];
                                $tcp = $tcp + $SsY5Courses[$i][2]*$SsY5Courses[$i][4];          
                                if ($SsY5Courses[$i][4] != 0){$tnup = $tnup + $SsY5Courses[$i][2];}
                            }else if ($sessionCounter == 6){
                                $tnu = $tnu + $SsY6Courses[$i][2];
                                $tcp = $tcp + $SsY6Courses[$i][2]*$SsY6Courses[$i][4];          
                                if ($SsY6Courses[$i][4] != 0){$tnup = $tnup + $SsY6Courses[$i][2];}
                            }else if ($sessionCounter == 7){
                                $tnu = $tnu + $SsY7Courses[$i][2];
                                $tcp = $tcp + $SsY7Courses[$i][2]*$SsY7Courses[$i][4];          
                                if ($SsY7Courses[$i][4] != 0){$tnup = $tnup + $SsY7Courses[$i][2];}
                            }else if ($sessionCounter == 8){
                                $tnu = $tnu + $SsY8Courses[$i][2];
                                $tcp = $tcp + $SsY8Courses[$i][2]*$SsY8Courses[$i][4];          
                                if ($SsY8Courses[$i][4] != 0){$tnup = $tnup + $SsY8Courses[$i][2];}

0 个答案:

没有答案