WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\Utils

ArrayUtils::natural_language_join() public WC 1.0

Join a string with a natural language conjunction at the end.

{} It's a method of the class: ArrayUtils{}

No Hooks.

Return

String. a string containing a list of items and a natural language conjuction.

Usage

$result = ArrayUtils::natural_language_join( $array, $enclose_items_with_quotes );
$array(array) (required)
The array to join together with the natural language conjunction.
$enclose_items_with_quotes(true|false)
Whether each item in the array should be enclosed within quotation marks.
Default: false

Code of ArrayUtils::natural_language_join() WC 5.8.0

public static function natural_language_join( $array, $enclose_items_with_quotes = false ) {
	if ( true === $enclose_items_with_quotes ) {
		$array = array_map(
			function( $item ) {
				return '"' . $item . '"';
			},
			$array
		);
	}
	$last = array_pop( $array );
	if ( $array ) {
		return sprintf(
			/* translators: 1: The first n-1 items of a list 2: the last item in the list. */
			__( '%1$s and %2$s', 'woocommerce' ),
			implode( ', ', $array ),
			$last
		);
	}
	return $last;
}