首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用爆炸变量对时间循环进行排序

问使用爆炸变量对时间循环进行排序
EN

Stack Overflow用户
提问于 2014-12-02 10:10:49
回答 1查看 127关注 0票数 0

我得到了以下内容,但是在结果中是一个长字符串,包含在该字符串中的是一个服务器名,我希望根据这个名称对结果进行排序,这可能吗?

代码语言:javascript
复制
    <?php
$dbQuery = mysql_query("SELECT * FROM opencall where cust_id = 'user.name@jpress' and status < 6  order by fixbyx asc") or die(mysql_error());//find call ref of open call with correct id
    while ($PRTGdbresults = mysql_fetch_array($dbQuery)){
    $SplitText = explode("\n", $probtext); //split the string by line break
    echo'<div class="row">';
    echo'<div class="inf_div" title="Current Server">';
            echo $SplitText[1]; //this is the server name I wish to sort by
        echo'</div></div>';
 }
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-02 10:14:02

您可以为排序定义自己的函数,然后将此函数与usort排序函数一起使用。

使用您提供的代码,我将简单地比较服务器名称的字符串,并按字母顺序对它们进行排序。这是密码;

代码语言:javascript
复制
<?php
    $dbQuery = mysql_query("SELECT * FROM opencall where cust_id = 'user.name@jpress' and status < 6  order by fixbyx asc") or die(mysql_error());
    $results = array();

    while ($PRTGdbresults = mysql_fetch_array($dbQuery)){
        array_push($results,$probtext);
    }

    usort($results, "sortProbtext");

    foreach($results as $key => $probtext){
        $SplitText = explode("\n", $probtext);
        echo'<div class="row">';
        echo'<div class="inf_div" title="Current Server">';
        echo $SplitText[1];
        echo'</div></div>';   
    }

    function sortProbtext($a, $b){
       $SplitTextA = explode("\n", $a);
       $SplitTextB = explode("\n", $b);
       if ($SplitTextA[1]  == $SplitTextB[1] ) {
          return 0;
       }
       return ($SplitTextA[1]  < $SplitTextB[1] ) ? -1 : 1;
    }
?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27246747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档