diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index 7c407a60..32503ff5 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -36,7 +36,7 @@ class SP_Event extends SP_Custom_Post{ $usecolumns = get_post_meta( $this->ID, 'sp_result_columns', true ); // Get results for all teams - $data = sp_array_combine( $teams, $results ); + $data = sp_array_combine( $teams, $results, true ); if ( $admin ): return array( $columns, $usecolumns, $data ); diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 4646d867..18f3d9e1 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -260,23 +260,31 @@ if ( !function_exists( 'sp_array_value' ) ) { } if ( !function_exists( 'sp_array_combine' ) ) { - function sp_array_combine( $keys = array(), $values = array() ) { + function sp_array_combine( $keys = array(), $values = array(), $key_order = false ) { if ( ! is_array( $keys ) ) return array(); if ( ! is_array( $values ) ) $values = array(); $output = array(); - foreach ( $values as $key => $value ): - if ( in_array( $key, $keys ) ): - $output[ $key ] = $value; - endif; - endforeach; - - foreach ( $keys as $key ): - if ( $key !== false && ! array_key_exists( $key, $output ) ) - $output[ $key ] = array(); - endforeach; + if ( $key_order ): + foreach( $keys as $key ): + if ( array_key_exists( $key, $values ) ) + $output[ $key ] = $values[ $key ]; + else + $output[ $key ] = array(); + endforeach; + else: + foreach ( $values as $key => $value ): + if ( in_array( $key, $keys ) ): + $output[ $key ] = $value; + endif; + endforeach; + foreach ( $keys as $key ): + if ( $key !== false && ! array_key_exists( $key, $output ) ) + $output[ $key ] = array(); + endforeach; + endif; return $output; } }