Converts a comma- or space-separated list of scalar values to an array.
Parameters
$input_listmixed[]|stringrequired- List of values.
Source
function wp_parse_list( $input_list ): array {
if ( ! is_array( $input_list ) ) {
$parsed_list = preg_split( '/[\s,]+/', $input_list, -1, PREG_SPLIT_NO_EMPTY );
return is_array( $parsed_list ) ? $parsed_list : array();
}
// Validate all entries of the list are scalar.
$input_list = array_filter( $input_list, 'is_scalar' );
return $input_list;
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |
Example:
Output: