.. _php-shouldusearrayfilter: .. _should-use-array\_filter(): Should Use array_filter() +++++++++++++++++++++++++ Should use `array_filter() `_. `array_filter() `_ is a native PHP function, that extract elements from an array, based on a custom call. Using `array_filter() `_ shortens your code, and allows for reusing the filtering logic across the application, instead of hard coding it every time. `array_filter() `_ is faster than `foreach() `_ (with or without the `isset() `_ test) with 3 elements or more, and it is significantly faster beyond 5 elements. Memory consumption is the same. .. code-block:: php See also `array_filter `_. Suggestions ___________ * Use array_filter() Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Php/ShouldUseArrayFilter | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Changed Behavior `, :ref:`Suggestions ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.0.7 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Slow (1 hour) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-xataface-php-shouldusearrayfilter`, :ref:`case-shopware-php-shouldusearrayfilter` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+