任何压缩方法都可以减少加载时间

时间:2015-07-03 06:26:50

标签: php

我需要更多压缩或更好一些,所以我可以减少加载时间。这已经将加载时间减慢到大约15秒,然后它曾经是o.0我需要它更紧凑以减少加载时间。有什么建议吗?

代码我不需要压缩他们只是在这里所以你知道发生了什么:

$dllinks = array($l720p1, $l720p2, $l720p3, $l720p4, $l720p5, $l720p6, $l720p7, $l720p8, $l720p9, $l720p10, $l720p11, $l720p12, $l720p13, $l720p14, $l720p15, $l720p16, $l720p17, $l720p18, $l720p19, $l720p20);

foreach ($Result as $r) {
        $name = $r['name'];
        $rating = $r['rating'];
        $imdbid = $r['imdbid'];
        $genre1 = $r['genre1'];
        if(!empty($r['genre2'])){ $genre2 = '- '.$r['genre2']; }
        $year = $r['year'];
        $plot = $r['plot'];
        $views = $r['views'];
        $downloads = $r['downloads'];
        $seasons = $r['seasons'];
        $l720p1 = $r['l720p1'];
        $l720p2 = $r['l720p2'];
        $l720p6 = $r['l720p6'];
        $l1080p1 = $r['l1080p1'];
        $l1080p2 = $r['l1080p2'];
    }

...

代码我需要压缩:

if(empty($dllinks[0])) { $dl720p1 = 'http://example.com'; } else { $dl720p1 = $l720p1; };
    if(empty($dllinks[1])) { $dl720p2 = 'http://example.com'; } else { $dl720p2 = $l720p2; };
    if(empty($dllinks[2])) { $dl720p3 = 'http://example.com'; } else { $dl720p3 = $l720p3; };
    if(empty($dllinks[3])) { $dl720p4 = 'http://example.com'; } else { $dl720p4 = $l720p4; };
    if(empty($dllinks[4])) { $dl720p5 = 'http://example.com'; } else { $dl720p5 = $l720p5; };
    if(empty($dllinks[5])) { $dl720p6 = 'http://example.com'; } else { $dl720p6 = $l720p6; };
    if(empty($dllinks[6])) { $dl720p7 = 'http://example.com'; } else { $dl720p7 = $l720p7; };
    if(empty($dllinks[7])) { $dl720p8 = 'http://example.com'; } else { $dl720p8 = $l720p8; };
    if(empty($dllinks[8])) { $dl720p9 = 'http://example.com'; } else { $dl720p9 = $l720p9; };
    if(empty($dllinks[9])) { $dl720p10 = 'http://example.com'; } else { $dl720p10 = $l720p10; };
    if(empty($dllinks[10])) { $dl720p11 = 'http://example.com'; } else { $dl720p11 = $l720p11; };
    if(empty($dllinks[11])) { $dl720p12 = 'http://example.com'; } else { $dl720p12 = $l720p12; };
    if(empty($dllinks[12])) { $dl720p13 = 'http://example.com'; } else { $dl720p13 = $l720p13; };
    if(empty($dllinks[13])) { $dl720p14 = 'http://example.com'; } else { $dl720p14 = $l720p14; };
    if(empty($dllinks[14])) { $dl720p15 = 'http://example.com'; } else { $dl720p15 = $l720p15; };
    if(empty($dllinks[15])) { $dl720p16 = 'http://example.com'; } else { $dl720p16 = $l720p16; };
    if(empty($dllinks[16])) { $dl720p17 = 'http://example.com'; } else { $dl720p17 = $l720p17; };
    if(empty($dllinks[17])) { $dl720p18 = 'http://example.com'; } else { $dl720p18 = $l720p18; };
    if(empty($dllinks[18])) { $dl720p19 = 'http://example.com'; } else { $dl720p19 = $l720p19; };
    if(empty($dllinks[19])) { $dl720p20 = 'http://example.com'; } else { $dl720p20 = $l720p20; };

更新:尝试:

for ($i = 1; $i <= 20; $i++) { 
    if(empty(${'dllinks' . [$i]})) {
        ${'dl720p' . $i} = 'example.com';
    } else {
        ${'dl720p' . $i} = ${'l720p' . $i};
    }
}

但是它给了我这么多错误,让我很难打开rror_log导致洪水泛滥!

1 个答案:

答案 0 :(得分:1)

如果你有类似的东西

$dllinks = array('l720p1' => $l720p1, 'l720p2' => $l720p2, 'l720p3' => $l720p3, 'l720p4' => $l720p4...);

你可以做迭代:

foreach ($dllinks as $varName => $value) {
    $varName2 = 'd'.$varName;

    if (empty($value)) {
        $$varName2 = 'http://example.com';
    } else {
        $$varName2 = $value;
    }
}

或者更好的是,使用数组键而不是单独的变量:

foreach ($dllinks as &$value) {
    if (empty($value)) {
        $value = 'http://example.com';
    }
}

...

echo "<a href='{$dllinks['l720p1']}'>Visit l720p1</a>";