龙空技术网

把瑞文测试的Excel的数据转换为代码,PHP代码实现

IT小厂总经理杨老师 134

前言:

而今咱们对“php代码换行”大约比较注意,咱们都需要剖析一些“php代码换行”的相关内容。那么小编同时在网络上网罗了一些对于“php代码换行””的相关知识,希望姐妹们能喜欢,同学们一起来学习一下吧!

客户需求是把Excel的分数和年龄对应的Excel数据展示在结果页面

解决思路分析:

纵坐标分数1-72, 横坐标年龄5.5-64

数据不具有连续性,写if、else判断要72x23个,有一些可以合并,大概还是100+个if else

换个思路,横竖就是二维数组,把excel的数据解析为二维数组即可,直接粘贴复制到记事本,用\n 换行分割为一层,用空格分割为二层数组

代码如下:

 $str = "54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6255  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6256  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6258  60  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6260  60  58  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6262  62  60  58  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6265  64  62  60  58  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6268  65  64  63  60  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6270  66  65  65  62  56  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6273  67  66  66  64  58  56  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6275  68  68  68  65  60  58  56  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6280  69  69  69  66  61  60  58  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6285  70  70  70  66  62  61  59  56  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6290  75  75  73  67  63  61  60  57  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 6292  80  80  75  67  64  62  60  58  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 6595  85  85  76  68  65  62  61  59  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 54  6798  88  86  77  68  66  63  61  60  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 58  68100 90  86  78  69  68  64  62  60  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 64  69102 92  87  78  70  70  64  62  61  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 54  66  70104 94  87  79  71  71  65  62  62  56  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 58  67  70105 95  88  80  72  71  65  63  62  56  55  54  <54 <54 <54 <54 <54 <54 <54 <54 64  69  71106 97  89  82  73  72  65  63  63  56  56  55  <54 <54 <54 <54 <54 <54 <54 54  65  70  71108 99  90  84  74  72  66  64  64  57  56  56  <54 <54 <54 <54 <54 <54 <54 58  67  71  72109 100 91  85  75  73  66  64  64  57  57  57  <54 <54 <54 <54 <54 <54 <54 62  68  72  73110 103 92  86  78  73  66  65  65  58  58  58  <54 <54 <54 <54 <54 <54 <54 64  69  73  74112 105 93  86  80  74  67  66  65  59  59  59  <54 <54 <54 <54 <54 <54 <54 65  70  73  75115 106 93  87  81  74  67  66  65  60  60  60  <54 <54 <54 <54 <54 <54 54  67  71  74  76116 108 94  88  82  75  67  66  66  61  60  61  <54 <54 <54 <54 <54 <54 58  68  72  75  77118 110 95  89  83  76  68  66  66  62  61  62  <54 <54 <54 <54 <54 <54 62  69  73  76  78120 111 95  90  83  78  68  67  66  62  62  62  <54 <54 <54 <54 <54 54  64  70  74  77  79123 112 96  91  84  80  68  67  67  63  63  63  <54 <54 <54 <54 <54 58  65  70  75  77  80125 113 97  92  85  81  69  67  67  63  64  64  <54 <54 <54 <54 <54 62  67  71  76  78  81126 114 98  93  86  82  69  67  67  64  64  64  <54 <54 <54 <54 54  64  68  72  77  79  81127 115 98  94  88  83  70  68  68  65  65  65  <54 <54 <54 <54 58  67  69  73  77  80  82128 116 99  95  90  83  71  68  68  65  65  65  <54 <54 <54 <54 62  69  70  74  78  81  83129 117 100 96  91  84  71  68  68  66  66  66  <54 <54 <54 <54 64  70  71  75  79  82  84130 117 101 96  92  85  72  69  69  66  66  66  <54 <54 <54 <54 65  71  72  77  79  83  85133 118 102 97  93  86  72  69  69  67  66  66  <54 <54 <54 54  67  72  73  78  80  85  85135 119 103 98  93  87  73  69  69  67  67  67  <54 54  54  58  69  73  74  79  80  85  86135+    120 103 98  94  88  74  70  70  68  67  67  54  55  58  62  70  74  75  80  81  86  86135+    122 104 99  95  88  75  73  72  68  68  68  58  62  62  63  71  76  76  81  82  86  87135+    123 105 99  96  89  76  75  74  69  68  68  61  64  64  65  72  77  77  82  84  86  88135+    124 106 100 98  89  78  76  75  70  69  69  63  65  65  67  73  78  79  83  85  87  89135+    125 108 103 99  90  80  77  76  71  69  69  65  67  67  69  74  79  80  84  85  89  90135+    126 109 105 100 91  82  77  76  71  70  70  67  69  69  70  75  80  82  85  86  90  91135+    127 110 106 101 93  84  78  77  72  71  71  68  70  70  71  76  83  83  86  86  91  92135+    128 112 108 102 94  85  79  78  72  71  71  70  71  71  72  77  85  85  87  87  92  93135+    129 115 110 103 95  90  80  79  73  72  72  71  72  72  73  78  86  86  88  89  93  94135+    130 120 112 104 96  92  83  80  73  72  72  72  73  73  74  79  87  88  90  90  94  95135+    131 124 114 105 97  94  85  82  74  73  73  73  74  74  75  80  88  90  90  91  95  96135+    132 125 115 106 98  95  90  84  75  74  73  74  75  75  76  82  89  91  91  91  96  98135+    134 126 120 108 99  96  91  85  80  74  73  75  76  76  77  83  90  92  92  92  97  99135+    135 128 122 110 100 98  93  86  82  75  74  76  77  77  78  85  91  93  93  93  98  100135+    135+    130 124 115 103 99  94  87  84  76  74  78  79  79  79  86  93  95  95  95  99  101135+    135+    135 125 116 105 100 95  89  85  78  75  80  80  80  81  87  94  97  97  97  100 102135+    135+    135+    126 118 106 102 96  90  90  79  78  81  82  82  84  88  96  98  98  98  101 103135+    135+    135+    128 119 108 104 98  92  92  80  80  82  85  85  86  90  98  99  100 100 102 104135+    135+    135+    130 120 110 105 99  94  94  85  85  83  86  87  88  92  100 100 101 101 103 105135+    135+    135+    132 123 112 106 100 95  95  90  88  86  88  89  90  94  101 102 102 102 104 107135+    135+    135+    133 125 114 107 103 98  98  95  90  88  90  91  92  96  102 103 103 103 106 109135+    135+    135+    134 130 115 108 105 100 100 98  95  91  91  93  95  98  104 105 105 106 107 110135+    135+    135+    135 132 120 110 110 105 103 100 96  94  94  95  97  100 106 108 108 108 109 112135+    135+    135+    135+    134 125 115 115 103 105 103 98  97  97  98  100 102 108 110 110 110 110 114135+    135+    135+    135+    135 124 120 120 110 108 105 100 100 100 100 101 105 110 112 112 112 112 116135+    135+    135+    135+    135+    130 125 122 113 110 108 105 102 102 102 103 108 112 113 113 113 114 117135+    135+    135+    135+    135+    135 130 124 115 115 110 110 106 106 106 107 110 114 115 115 116 117 118135+    135+    135+    135+    135+    135+        125 120 120 115 115 108 108 108 109 113 118 118 119 119 119 120135+    135+    135+    135+    135+    135+    135 130 125 125 120 120 114 114 114 115 116 120 120 121 121 121 123135+    135+    135+    135+    135+    135+    135+    135 130 130 125 125 116 116 116 117 119 124 124 124 125 125 127135+    135+    135+    135+    135+    135+    135+    135+    135 135 130 130 122 122 122 123 123 127 127 128 130 130 132135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    133 133 128 128 128 128 129 129 132 132 133 133 133135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    135 135 135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    135+";$arr = explode("\n",$str);$arr = array_filter($arr);$arr = array_values($arr);foreach($arr as &$val){    $arr2 = explode(" ",$val);    $arr2 = array_filter($arr2);    $arr2 = array_values($arr2);    $val = $arr2;}

第二步,因为横坐标是有区间的40-44都算一个key,单独要写一下这部分逻辑

if($age <= 5.5){        $age_key=0;    }elseif($age <= 6.5){        $age_key=1;    }elseif($age <= 7.5){        $age_key=2;    }elseif($age <= 8.5){        $age_key=3;    }elseif($age <= 9.5){        $age_key=4;    }elseif($age <= 10.5){        $age_key=5;    }elseif($age <= 11.5){        $age_key=6;    }elseif($age <= 12.5){        $age_key=7;    }elseif($age <= 13.5){        $age_key=8;    }elseif($age <= 14.5){        $age_key=9;    }elseif($age <= 15.5){        $age_key=10;    }elseif($age <= 16.5){        $age_key=11;    }elseif($age <= 17.5){        $age_key=12;    }elseif($age <= 18.5){        $age_key=13;    }elseif($age > 18.5 &&$age <= 24){        $age_key=14;    }elseif($age >= 25 &&$age <= 29){        $age_key=15;    }elseif($age >= 30 &&$age <= 34){        $age_key=16;    }elseif($age >= 35 &&$age <= 39){        $age_key=17;    }elseif($age >= 40 &&$age <= 44){        $age_key=18;    }elseif($age >= 45 &&$age <= 49){        $age_key=19;    }elseif($age >= 50 &&$age <= 54){        $age_key=20;    }elseif($age >= 55 &&$age <= 59){        $age_key=21;    }else{        //if($age >= 60 &&$age <= 64)        $age_key=22;    }

最后测试和检查一下,score是有可能大于72的,key越界,所以限制一下

 $score > 72 ? $score=72:"";

最终版本

private function getZhishang($score,$age){    $str = "54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6255  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6256  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6258  60  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6260  60  58  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6262  62  60  58  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6265  64  62  60  58  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6268  65  64  63  60  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6270  66  65  65  62  56  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6273  67  66  66  64  58  56  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6275  68  68  68  65  60  58  56  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6280  69  69  69  66  61  60  58  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6285  70  70  70  66  62  61  59  56  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <6290  75  75  73  67  63  61  60  57  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 6292  80  80  75  67  64  62  60  58  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 6595  85  85  76  68  65  62  61  59  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 54  6798  88  86  77  68  66  63  61  60  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 58  68100 90  86  78  69  68  64  62  60  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 <54 64  69102 92  87  78  70  70  64  62  61  55  54  <54 <54 <54 <54 <54 <54 <54 <54 <54 54  66  70104 94  87  79  71  71  65  62  62  56  55  <54 <54 <54 <54 <54 <54 <54 <54 <54 58  67  70105 95  88  80  72  71  65  63  62  56  55  54  <54 <54 <54 <54 <54 <54 <54 <54 64  69  71106 97  89  82  73  72  65  63  63  56  56  55  <54 <54 <54 <54 <54 <54 <54 54  65  70  71108 99  90  84  74  72  66  64  64  57  56  56  <54 <54 <54 <54 <54 <54 <54 58  67  71  72109 100 91  85  75  73  66  64  64  57  57  57  <54 <54 <54 <54 <54 <54 <54 62  68  72  73110 103 92  86  78  73  66  65  65  58  58  58  <54 <54 <54 <54 <54 <54 <54 64  69  73  74112 105 93  86  80  74  67  66  65  59  59  59  <54 <54 <54 <54 <54 <54 <54 65  70  73  75115 106 93  87  81  74  67  66  65  60  60  60  <54 <54 <54 <54 <54 <54 54  67  71  74  76116 108 94  88  82  75  67  66  66  61  60  61  <54 <54 <54 <54 <54 <54 58  68  72  75  77118 110 95  89  83  76  68  66  66  62  61  62  <54 <54 <54 <54 <54 <54 62  69  73  76  78120 111 95  90  83  78  68  67  66  62  62  62  <54 <54 <54 <54 <54 54  64  70  74  77  79123 112 96  91  84  80  68  67  67  63  63  63  <54 <54 <54 <54 <54 58  65  70  75  77  80125 113 97  92  85  81  69  67  67  63  64  64  <54 <54 <54 <54 <54 62  67  71  76  78  81126 114 98  93  86  82  69  67  67  64  64  64  <54 <54 <54 <54 54  64  68  72  77  79  81127 115 98  94  88  83  70  68  68  65  65  65  <54 <54 <54 <54 58  67  69  73  77  80  82128 116 99  95  90  83  71  68  68  65  65  65  <54 <54 <54 <54 62  69  70  74  78  81  83129 117 100 96  91  84  71  68  68  66  66  66  <54 <54 <54 <54 64  70  71  75  79  82  84130 117 101 96  92  85  72  69  69  66  66  66  <54 <54 <54 <54 65  71  72  77  79  83  85133 118 102 97  93  86  72  69  69  67  66  66  <54 <54 <54 54  67  72  73  78  80  85  85135 119 103 98  93  87  73  69  69  67  67  67  <54 54  54  58  69  73  74  79  80  85  86135+    120 103 98  94  88  74  70  70  68  67  67  54  55  58  62  70  74  75  80  81  86  86135+    122 104 99  95  88  75  73  72  68  68  68  58  62  62  63  71  76  76  81  82  86  87135+    123 105 99  96  89  76  75  74  69  68  68  61  64  64  65  72  77  77  82  84  86  88135+    124 106 100 98  89  78  76  75  70  69  69  63  65  65  67  73  78  79  83  85  87  89135+    125 108 103 99  90  80  77  76  71  69  69  65  67  67  69  74  79  80  84  85  89  90135+    126 109 105 100 91  82  77  76  71  70  70  67  69  69  70  75  80  82  85  86  90  91135+    127 110 106 101 93  84  78  77  72  71  71  68  70  70  71  76  83  83  86  86  91  92135+    128 112 108 102 94  85  79  78  72  71  71  70  71  71  72  77  85  85  87  87  92  93135+    129 115 110 103 95  90  80  79  73  72  72  71  72  72  73  78  86  86  88  89  93  94135+    130 120 112 104 96  92  83  80  73  72  72  72  73  73  74  79  87  88  90  90  94  95135+    131 124 114 105 97  94  85  82  74  73  73  73  74  74  75  80  88  90  90  91  95  96135+    132 125 115 106 98  95  90  84  75  74  73  74  75  75  76  82  89  91  91  91  96  98135+    134 126 120 108 99  96  91  85  80  74  73  75  76  76  77  83  90  92  92  92  97  99135+    135 128 122 110 100 98  93  86  82  75  74  76  77  77  78  85  91  93  93  93  98  100135+    135+    130 124 115 103 99  94  87  84  76  74  78  79  79  79  86  93  95  95  95  99  101135+    135+    135 125 116 105 100 95  89  85  78  75  80  80  80  81  87  94  97  97  97  100 102135+    135+    135+    126 118 106 102 96  90  90  79  78  81  82  82  84  88  96  98  98  98  101 103135+    135+    135+    128 119 108 104 98  92  92  80  80  82  85  85  86  90  98  99  100 100 102 104135+    135+    135+    130 120 110 105 99  94  94  85  85  83  86  87  88  92  100 100 101 101 103 105135+    135+    135+    132 123 112 106 100 95  95  90  88  86  88  89  90  94  101 102 102 102 104 107135+    135+    135+    133 125 114 107 103 98  98  95  90  88  90  91  92  96  102 103 103 103 106 109135+    135+    135+    134 130 115 108 105 100 100 98  95  91  91  93  95  98  104 105 105 106 107 110135+    135+    135+    135 132 120 110 110 105 103 100 96  94  94  95  97  100 106 108 108 108 109 112135+    135+    135+    135+    134 125 115 115 103 105 103 98  97  97  98  100 102 108 110 110 110 110 114135+    135+    135+    135+    135 124 120 120 110 108 105 100 100 100 100 101 105 110 112 112 112 112 116135+    135+    135+    135+    135+    130 125 122 113 110 108 105 102 102 102 103 108 112 113 113 113 114 117135+    135+    135+    135+    135+    135 130 124 115 115 110 110 106 106 106 107 110 114 115 115 116 117 118135+    135+    135+    135+    135+    135+        125 120 120 115 115 108 108 108 109 113 118 118 119 119 119 120135+    135+    135+    135+    135+    135+    135 130 125 125 120 120 114 114 114 115 116 120 120 121 121 121 123135+    135+    135+    135+    135+    135+    135+    135 130 130 125 125 116 116 116 117 119 124 124 124 125 125 127135+    135+    135+    135+    135+    135+    135+    135+    135 135 130 130 122 122 122 123 123 127 127 128 130 130 132135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    133 133 128 128 128 128 129 129 132 132 133 133 133135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    135 135 135+    135+    135+    135+    135+    135+    135+    135+    135+    135+    135+";$arr = explode("\n",$str);$arr = array_filter($arr);$arr = array_values($arr);foreach($arr as &$val){    $arr2 = explode(" ",$val);    $arr2 = array_filter($arr2);    $arr2 = array_values($arr2);    $val = $arr2;}    if($age <= 5.5){        $age_key=0;    }elseif($age <= 6.5){        $age_key=1;    }elseif($age <= 7.5){        $age_key=2;    }elseif($age <= 8.5){        $age_key=3;    }elseif($age <= 9.5){        $age_key=4;    }elseif($age <= 10.5){        $age_key=5;    }elseif($age <= 11.5){        $age_key=6;    }elseif($age <= 12.5){        $age_key=7;    }elseif($age <= 13.5){        $age_key=8;    }elseif($age <= 14.5){        $age_key=9;    }elseif($age <= 15.5){        $age_key=10;    }elseif($age <= 16.5){        $age_key=11;    }elseif($age <= 17.5){        $age_key=12;    }elseif($age <= 18.5){        $age_key=13;    }elseif($age > 18.5 &&$age <= 24){        $age_key=14;    }elseif($age >= 25 &&$age <= 29){        $age_key=15;    }elseif($age >= 30 &&$age <= 34){        $age_key=16;    }elseif($age >= 35 &&$age <= 39){        $age_key=17;    }elseif($age >= 40 &&$age <= 44){        $age_key=18;    }elseif($age >= 45 &&$age <= 49){        $age_key=19;    }elseif($age >= 50 &&$age <= 54){        $age_key=20;    }elseif($age >= 55 &&$age <= 59){        $age_key=21;    }else{        //if($age >= 60 &&$age <= 64)        $age_key=22;    }        $score > 72 ? $score=72:"";    return $arr[$score-1][$age_key]; }

最终运行结果

标签: #php代码换行