Tribe__Utils__Array::list_to_array( mixed $value, string $sep = ',' )
Converts a list to an array filtering out empty string elements.
Contents
Parameters
- $value
-
(mixed) (Required) A string representing a list of values separated by the specified separator or an array. If the list is a string (e.g. a CSV list) then it will urldecoded before processing.
- $sep
-
(string) (Optional) The char(s) separating the list elements; will be ignored if the list is an array.
Default value: ','
Return
(array) An array of list elements.
Source
File: src/Tribe/Utils/Array.php
public static function list_to_array( $value, $sep = ',' ) {
// since we might receive URL encoded strings for CSV lists let's URL decode them first
$value = is_array( $value ) ? $value : urldecode( $value );
$sep = is_string( $sep ) ? $sep : ',';
if ( $value === null || $value === '' ) {
return array();
}
if ( ! is_array( $value ) ) {
$value = preg_split( '/\\s*' . preg_quote( $sep ) . '\\s*/', $value );
}
$filtered = array();
foreach ( $value as $v ) {
if ( '' === $v ) {
continue;
}
$filtered[] = is_numeric( $v ) ? $v + 0 : $v;
}
return $filtered;
}