class FilterArray

Provides methods to filter arrays.

Hierarchy

Expanded class hierarchy of FilterArray

Related topics

10 files declare their use of FilterArray
Connection.php in core/modules/sqlite/src/Driver/Database/sqlite/Connection.php
Datelist.php in core/lib/Drupal/Core/Datetime/Element/Datelist.php
FieldInstanceOptionTranslation.php in core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceOptionTranslation.php
FieldOptionTranslation.php in core/modules/field/src/Plugin/migrate/process/d6/FieldOptionTranslation.php
FieldSettings.php in core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php

... See full list

File

core/lib/Drupal/Component/Utility/FilterArray.php, line 12

Namespace

Drupal\Component\Utility
View source
class FilterArray {
  
  /**
   * Removes empty strings from an array.
   *
   * This method removes all empty strings from the input array. This is
   * particularly useful to preserve 0 whilst filtering other falsy values. The
   * values are first cast to a string before comparison.
   *
   * @param array $value
   *   The array to filter.
   *
   * @return array
   *   The filtered array.
   */
  public static function removeEmptyStrings(array $value) : array {
    return array_filter($value, static fn($item) => (string) $item !== '');
  }

}

Members

Title Sort descending Modifiers Object type Summary
FilterArray::removeEmptyStrings public static function Removes empty strings from an array.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.