PHP';FOREACH&x27;排序或筛选
希望有人能提供帮助,我有以下代码,并希望根据字段#(u BOOKINGFORMCUSTOM{dbem_race_class}进行排序,这可能吗?如果没有,是否有根据字段内容过滤结果的方法PHP';FOREACH&x27;排序或筛选,php,arrays,sorting,filter,foreach,Php,Arrays,Sorting,Filter,Foreach,希望有人能提供帮助,我有以下代码,并希望根据字段#(u BOOKINGFORMCUSTOM{dbem_race_class}进行排序,这可能吗?如果没有,是否有根据字段内容过滤结果的方法 $people = array(); $EM_Bookings = $EM_Event->get_bookings(); if( count($EM_Bookings->bookings) > 0 ){ ?> <ul class="event-attend
$people = array();
$EM_Bookings = $EM_Event->get_bookings();
if( count($EM_Bookings->bookings) > 0 ){
?>
<ul class="event-attendees">
<?php
echo '<table style="width: 100%;" cellpadding="25" border="1">
<tr style="background-color:red; color:white"</tr>
<td style="vertical-align: top">Driver</td>
<td style="vertical-align: top">Race Type</td>
<td style="vertical-align: top">Car Manufacturer</td>
<td style="vertical-align: top">Car Model</td>
<td style="vertical-align: top">Engine Manufacturer</td>
<td style="vertical-align: top">PT Number</td>
</tr>';
$guest_bookings = get_option('dbem_bookings_registration_disable');
$guest_booking_user = get_option('dbem_bookings_registration_user');
foreach( $EM_Bookings as $EM_Booking){
if($EM_Booking->booking_status == 1){
$attendees_list = "";
$attendees = $EM_Booking->booking_meta['attendees'];
if ( !empty($attendees) ){
foreach($attendees as $key => $value) {
$attendees_list = "<ul style='padding-left:50px'>";
foreach($value as $key_attendee => $value_attendee) {
$attendees_list .= "".$value_attendee["attendee_name"]."";
}
$attendees_list .= "</ul>";
}
}
echo '<tr><td style="vertical-align: top">'. $EM_Booking->get_person()->get_name() .' </td><td style="vertical-align: top"> '. $EM_Booking->output("#_BOOKINGFORMCUSTOM{dbem_race_class}").' </td><td style="vertical-align: top"> '. $EM_Booking->output("#_BOOKINGFORMCUSTOM{dbem_car_manufacturer}").' </td><td style="vertical-align: top"> '. $EM_Booking->output("#_BOOKINGFORMCUSTOM{dbem_car_model}").' </td><td style="vertical-align: top"> '. $EM_Booking->output("#_BOOKINGFORMCUSTOM{dbem_engine_manufacturer}"). '</td><td style="vertical-align: top"> '. $EM_Booking->output("#_BOOKINGFORMCUSTOM{dbem_pt__number}").' </td></tr>'.$attendees_list.'</p>';
}
}
echo '</table>';
?>
</ul>
<?php
}
$people=array();
$EM_Bookings=$EM_Event->get_Bookings();
如果(计数($EM\U预订->预订)>0){
?>
你应该能用usort做点什么
大致如下:
usort($EM_Bookings, "booking_sorter");
function booking_sorter($a, $b)
{
return strcmp($a->output("#_BOOKINGFORMCUSTOM{dbem_race_class}"), $b->output("#_BOOKINGFORMCUSTOM{dbem_race_class}"));
}
对于过滤,您可以使用array_filter执行基本相同的操作
感谢您提供的链接和信息,但它似乎仍然无法正常工作。我已尝试将usort放在多个位置,但它仍然无法在race_类中排序。我查看了您发送的筛选链接,无法找到解决方法。还有其他想法,请提前感谢。。。