我有以下数组:
$tickets[] = array( 'event_id', 'ticket_name','holder_name', 'order_id', 'ticket_id', 'security_code')
我希望能够按'event_id'
对输出进行分组并获取:
Event_ID 1
-> Ticket ID 1 ......
-> Ticket ID 2 .....
Event_ID 2
-> Ticket ID 3......
到目前为止我已经知道了:
foreach ($tickets as $key => $event ) {
$tickets[$key]['event_id'] = $event;
这看起来是否正确?
由于
编辑:综合解决方案1。
`
<?php
do_action( 'tribe_tickets_ticket_email_top' );
$groupedEvents = array();
foreach($tickets as $key => $ticket)
{
$groupedEvents['Event_ID_'.$ticket['event_id']][] = $ticket['ticket_id'];
if ( function_exists( 'tribe_get_venue_id' ) ) {
$event = get_post( $groupedEvents['Event_ID'] );
$venue_id = tribe_get_venue_id( $event->ID );
if ( ! empty( $venue_id ) ) {
$venue = get_post( $venue_id );
}
$venue_label = tribe_get_venue_label_singular();
$venue_name = $venue_phone = $venue_address = $venue_city = $venue_web = '';
if ( ! empty( $venue ) ) {
$venue_name = $venue->post_title;
$venue_phone = get_post_meta( $venue_id, '_VenuePhone', true );
$venue_address = get_post_meta( $venue_id, '_VenueAddress', true );
$venue_city = get_post_meta( $venue_id, '_VenueCity', true );
$venue_web = get_post_meta( $venue_id, '_VenueURL', true );
}
}
<?php echo $venue_name; ?>
<?php echo $venue_address; ?>
<?php echo $venue_city; ?>
<?php echo $venue_phone; ?>
<a href="<?php echo esc_url( $venue_web ) ?>" ><?php echo $venue_web; ?></a>
}
<?php esc_html_e( 'Ticket #', 'event-tickets' ); ?> <?php echo $groupedEvents['ticket_id']; ?>
<?php esc_html_e( 'Ticket Type', 'event-tickets' ); ?>
<?php echo $groupedEvents['ticket_name']; ?>
<?php echo $groupedEvents['holder_name']; ?>
<?php esc_html_e( 'Security Code', 'event-tickets' ); ?>
<?php echo $groupedEvents['security_code']; ?>
?>`