Php 使用分解变量对while循环进行排序

Php 使用分解变量对while循环进行排序,php,sorting,Php,Sorting,我得到了以下结果,但结果中有一个长字符串,该字符串中包含一个服务器名称,我希望根据该名称对结果进行排序,这可能吗 <?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 c

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

    <?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>';
 }
?>

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

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

<?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;
    }
?>