profile picture

2 pages tagged with "array"

Never use array_merge in a loop

November 10, 2020

blog-cover

Using array_merge inside a loop is a performance killer. The spread operator will help you to improve this by flatting the array.

Using array_merge 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 array_merge function in a loop like: <?php $lists = [ [1, 2], [3, 4], [5, 6], ]; $merged = []; foreach…

Typed arrays in PHP

October 13, 2020

blog-cover

Argument unpacking, function variable argument list, and variadics function.

Argument unpacking, function variable argument list, and variadics function. The perfect combination Argument unpacking: Instead of passing the argument itself to the function, the elements it contains will be passed (as individual arguments). Function variable argument list: The arguments will be…