Automattic\WooCommerce\Utilities

StringUtil::to_sql_list()public staticWC 1.0

Convert an array of values to a list suitable for a SQL "IN" statement (so comma separated and delimited by parenthesis). e.g.: [1,2,3] --> (1,2,3)

Method of the class: StringUtil{}

No Hooks.

Returns

String. A parenthesized and comma-separated string generated from the values.

Usage

$result = StringUtil::to_sql_list( $values );
$values(array) (required)
The values to convert.

StringUtil::to_sql_list() code WC 9.8.4

public static function to_sql_list( array $values ) {
	if ( empty( $values ) ) {
            // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
		throw new \InvalidArgumentException( self::class_name_without_namespace( __CLASS__ ) . '::' . __FUNCTION__ . ': the values array is empty' );
	}

	return '(' . implode( ',', $values ) . ')';
}