.. _structures-usearrayfunctions: .. _use-array-functions: Use Array Functions +++++++++++++++++++ There are a lot of native PHP functions for arrays. It is often faster to take advantage of them than write a loop. * `array_push() `_ : use `array_merge() `_ * `array_slice() `_ : use `array_chunk() `_ * index access : use `array_column() `_ * append `[]`: use `array_merge() `_ * addition : use `array_sum() `_ * multiplication : use `array_product() `_ * concatenation : use `implode() `_ * ifthen : use `array_filter() `_ * extract one index $s['index'] : use `array_column() `_ * apply a method to each element : use `array_map() `_ or `array_walk() `_ .. code-block:: php See also `Array Functions `_ and :ref:`No array_merge() In Loops `. Connex PHP features ------------------- + `class `_ Suggestions ___________ * Remove the loop and use a native PHP function * Add more expressions to the loop : batching multiple operations in one loop makes it more interesting than running separates loops. Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Structures/UseArrayFunctions | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Changed Behavior `, :ref:`Suggestions ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.8.8 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+