基于数字排序PHP数组

时间:2014-07-02 16:08:35

标签: php arrays sorting

我正在努力让“下载”页面正常运行。我从文件中获取了构建号和详细信息,并且我希望使用该构建号对数组进行排序,当前0.0.2高于1.0.3,并且在它上升时始终保持构建号。您可以在http://tattyseal.com/files/zaet

看到该页面
<?php
    echo "<table border=0 style='text-align:left;border-spacing: 40px 0;'>";
    echo "<tbody>";
    echo "<img src='logoFile.png'/>";
    echo "<h2>Promotions</h2>";
    echo "<tr>";
    echo "<th>Promotion</th>";
    echo "<th>Version</th>";
    echo "<th>Minecraft</th>";
    echo "<th>Downloads</th>";
    echo "</tr>";

    echo "<tr>";
    echo "<td>1.7.2-Recommend</td>";
    echo "<td>0.0.2</td>";
    echo "<td>1.7.2</td>";
    echo "<td>(<a href='http://ts.tattyseal.com:8080/job/Zaet/2/artifact/build/libs/Zaet-dev-0.0.2.jar'>Universal</a>) (<a href='http://ts.tattyseal.com:8080/job/Zaet/2/artifact/build/libs/Zaet-dev-0.0.2.jar'>Deobf</a>) (<a href='http://ts.tattyseal.com:8080/job/Zaet/2/artifact/build/libs/Zaet-src-0.0.2.jar'>Src</a>)";
    echo "</tr>";
    echo "</tbody>";
    echo "</table>";

    echo "<table border=0 style='text-align:left;border-spacing: 40px 0;'>";
    echo "<tbody>";
    echo "<tr>";
    echo "<h2>1.7.2 Downloads - Anything that is not Recommended can be unstable, there is a possibility of World Corruption</h2>";
    echo "<th>Version</th>";
    echo "<th>Minecraft</th>";
    echo "<th>Time</th>";
    echo "<th>Downloads</th>";
    echo "</tr>";

    $information = array();

    $iterator = new RecursiveDirectoryIterator('versions');
    foreach(new RecursiveIteratorIterator($iterator) as $filename => $file)
    {
        if (strpos($filename,'info') !== false)
        {
            array_push($information, file_get_contents($filename));
        }
    }

    sort($information);

    $information = array_reverse($information);

    $info = $information;

    $versions = array();

    foreach($info as $i)
    {
        $array = explode(",", $i);  

        foreach($array as $line)
        {           
            if(strpos($line, 'version') !== false)
            {
                if(strpos($line, 'mcversion') === false)
                {
                    $array2 = explode(": ", $line);

                    array_push($versions, $array2[1]);
                }
            }
        }
    }

    foreach($information as $info)
    {
        $array = explode(",", $info);

        $mcversion = "";
        $version = "";
        $date = "";
        $build = "";

        foreach($array as $line)
        {           
            if(strpos($line, 'mcversion') !== false)
            {
                $array3 = explode(": ", $line);
                $mcversion = $array3[1];
            }

            if(strpos($line, 'version') !== false)
            {
                $array3 = explode(": ", $line);
                $version = $array3[1];
            }

            if(strpos($line, 'date') !== false)
            {
                $array3 = explode(": ", $line);
                $date = $array3[1];
            }

            if(strpos($line, 'build') !== false)
            {
                $array3 = explode(": ", $line);
                $build = $array3[1];
            }
        }

        echo "<tr><td>$version</td><td>$mcversion</td><td>$date</td><td>" . "(<a href='http://ts.tattyseal.com:8080/job/Zaet/$build/changes'>Changelog</a>) (<a href='http://ts.tattyseal.com:8080/job/Zaet/$build/artifact/build/libs/Zaet-dev-0.0.$build.jar'>Deobf</a>) (<a href='http://ts.tattyseal.com:8080/job/Zaet/$build/artifact/build/libs/Zaet-src-0.0.$build.jar'>Src</a>) (<a href='http://ts.tattyseal.com:8080/job/Zaet/$build/artifact/build/libs/Zaet-mod-0.0.$build.jar'>Universal</a>)</td></tr>";
    }

    echo "</tbody>";
    echo "</table>";
?>

由于

0 个答案:

没有答案