我有一个wordpress网站,我正试图从按字母顺序(希腊语)的表中获得结果。我试过了,但没有用。我想我错过了什么,但我想不起来。下面是代码:
if($homeplayers) {
asort($homeplayers);
$i = 1; foreach ($homeplayers as $homeplayer) {
$output .= '<tr>';
$output .= '<td style="vertical-align:top;word-wrap:break-word;">';
$output .= leagueengine_fetch_player_emblem($homeplayer->player_id).leagueengine_fetch_data_from_id($homeplayer->player_id,'data_value' );
$output .= '</td>';
$output .= '<td style="text-align:center;vertical-align:top;">';
if(isset($_POST['import_last_home_lineups']) && in_array($homeplayer->player_id, $home_app)) {
$output .= '<input class="homeplayers" name="homeplayers[]" type="checkbox" checked="checked" value="'.$homeplayer->player_id.'">';
} else {
$output .= '<input class="homeplayers" name="homeplayers[]" type="checkbox" '.leagueengine_isplaying_tournament($tournament_id,$match_id,$homeplayer->player_id).' value="'.$homeplayer->player_id.'">';
}
$output .= '</td>';
$i++;
}
$output .= '<td></td>';
$output .= '</tr>';
}
您正在尝试使用asort
对对象进行排序,但是该函数不知道您希望如何排序....您需要一个自定义排序函数
usort($homeplayers, "sorter");
function sorter($a,$b){
// assuming ->player_name is the correct variable
return strcmp($a->player_name, $b->player_name);
}
来源:其他问题和php文档