PHP内部排序,而
我希望PHP内部排序,而,php,sorting,while-loop,Php,Sorting,While Loop,我希望echo按$match\u count的值排序。最高的数字应该在顶部 while($row = mysql_fetch_array($result)) { $num_kanal = count(explode(' ', $row['kanaler'])); $pr_kanal = $row['pris'] / $num_kanal; $pr_kanal = number_format((float)$pr_kanal, 2, '.', ''); $far
echo
按$match\u count
的值排序。最高的数字应该在顶部
while($row = mysql_fetch_array($result)) {
$num_kanal = count(explode(' ', $row['kanaler']));
$pr_kanal = $row['pris'] / $num_kanal;
$pr_kanal = number_format((float)$pr_kanal, 2, '.', '');
$farve = '#6a6a6a;';
if ($_POST['kanaler']) {
$getkan = implode($_POST['kanaler'], ' ');
$kan = $row['kanaler'];
$match_count = count(TheMatch($kan, $getkan));
$match = ' Match = '.$match_count;
}
// I WANT THIS ECHO TO BE SORT BY THE VALUE OF '$match_count' HIGEST NR IN TOP //
echo'<tr>
<td style="background-color:'.$farve.'"><p>
' . $row['udbyder'] . ' '.$_POST['kanaler'].'
</p></td>
</tr>';
}
}
while($row=mysql\u fetch\u array($result)){
$num_kanal=count(分解(“”,$row['kanaler']);
$pr_kanal=$row['pris']/$num_kanal;
$pr_kanal=数字_格式((浮点)$pr_kanal,2'.'','');
$farve=“#6a6a;”;
如果($_POST['kanaler'])){
$getkan=内爆($_POST['kanaler'],'';
$kan=$row['kanaler'];
$match_count=count(匹配($kan,$getkan));
$match='match='。$match\u计数;
}
//我希望此回音按顶部最高NR的“$match\u count”值排序//
回声'
“.$row['udbyder']”.$\U POST['kanaler']”
';
}
}
在迭代数组时,必须缓冲输出/值,对其排序,然后打印。大概是这样的:
$results = array();
while($row = ...) {
...
$results[] = array($match_count, '<tr><td style="background-color:...</tr>');
}
uasort($results, my_comp);
foreach($results as $result)
echo $result[1];
$results=array();
而($row=…){
...
$results[]=array($match_count,您也可以使用array_multisort:
<?php
array_multisort($match_count, SORT_DESC, $array_values_to_print);
foreach ($match_count as $result) {
echo '<tr><td style="background-color:...</tr>';
}
?>
第一个数组确定索引
<?php
array_multisort($match_count, SORT_DESC, $array_values_to_print);
foreach ($match_count as $result) {
echo '<tr><td style="background-color:...</tr>';
}
?>