'foo', 'item_2' => 'bar' ) * * array_insert_after( $array, 'item_1', array( 'item_1.5' => 'w00t' ) ) * * becomes * * array( 'item_1' => 'foo', 'item_1.5' => 'w00t', 'item_2' => 'bar' ) * * @since 2.2.0 * @param array $array array to insert the given element into * @param string $insert_key key to insert given element after * @param array $element element to insert into array * @return array */ public static function array_insert_after( Array $array, $insert_key, Array $element ) { $new_array = array(); foreach ( $array as $key => $value ) { $new_array[ $key ] = $value; if ( $insert_key == $key ) { foreach ( $element as $k => $v ) { $new_array[ $k ] = $v; } } } return $new_array; } /** * Lists an array as text. * * Takes an array and returns a list like "one, two, three, and four" * with a (mandatory) oxford comma. * * @since 5.2.0 * * @param array $items items to list * @param string|null $conjunction coordinating conjunction, like "or" or "and" * @param string $separator list separator, like a comma * @return string */ public static function list_array_items( array $items, $conjunction = null, $separator = '' ) { if ( ! is_string( $conjunction ) ) { $conjunction = _x( 'and', 'coordinating conjunction for a list of items: a, b, and c', 'woocommerce-square' ); } // append the conjunction to the last item if ( count( $items ) > 1 ) { $last_item = array_pop( $items ); array_push( $items, trim( "{$conjunction} {$last_item}" ) ); // only use a comma if needed and no separator was passed if ( count( $items ) < 3 ) { $separator = ' '; } elseif ( ! is_string( $separator ) || '' === $separator ) { $separator = ', '; } } return implode( $separator, $items ); } }