================================================================================ NEVER USE ARRAY_MERGE IN A LOOP ================================================================================ Date: 2020-11-10 Tags: php, clean-code, refactoring URL: https://chemaclass.com/blog/array-merge-in-loop/ -------------------------------------------------------------------------------- Using array_merge inside a loop is a performance killer. The spread operator will help you to improve this by flatting the array. Using arraymerge inside a loop is a performance killer. The spread operator will help you to improve this by flatting the array. FLATTENING A ONE-LEVEL ARRAY -------------------------------------------------------------------------------- I have seen people using the arraymerge function in a loop like: [1, 2], 'key-2' => [3, 4], 'key-3' => [5, 6], ]; In that case, you will need to unpack its values: [ 1, [2], 'key-2' => [ 3, [ 'key-3' => [4, 5], ], ], ], 6, 'key-4' => [7, 8], ]; In these cases, you might want to use the internal standard library: