1.2.400. Ellipsis Merge

Ellipsis are slower than array_merge().

The speed up is significative when the merge happen inside a loop. There, array_merge() is an order of magnitude faster.

This is a micro optimisation. The larger and numerous the arrays, the better the speed gain.

<?php

// slow
$all = array_merge($array1, $array2);

// very slow
$all = array(...$array1, ...$array2);

?>

1.2.400.1. Suggestions

  • Use array_merge()

1.2.400.2. Specs

Short name

Performances/EllipsisMerge

Rulesets

All, Changed Behavior, Performances

Exakat since

2.5.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

merge, ellipsis, micro-optimisation

Available in

Entreprise Edition, Exakat Cloud