Tribe__Utils__Array::flatten( array $array )
Flattens an array transforming each value that is an array and only contains one element into that one element.
Contents
Typical use case is to flatten arrays like those returned by get_post_meta( $id ). Empty arrays are replaced with an empty string.
Parameters
- $array
-
(array) (Required) The array to flatten.
Return
(array) The flattened array.
Source
File: src/Tribe/Utils/Array.php
public static function flatten( array $array ) {
foreach ( $array as $key => &$value ) {
if ( ! is_array( $value ) ) {
continue;
}
$count = count( $value );
switch ( $count ) {
case 0:
$value = '';
break;
case 1:
$value = reset( $value );
break;
default:
break;
}
}
return $array;
}
Changelog
| Version | Description |
|---|---|
| 4.9.5 | Introduced. |