1.2.1129. Skip Empty Array

When collecting arrays to be merged, it is faster to skip the empty arrays, rather than let array_merge() process them. This also works with array_merge_recursive().

This is a micro-optimisation. It is more efficient with larger arrays.

<?php

$all = [];
foreach($source as $array) {
     // $array is an array in this example
     if (empty($array)) {
             continue;
     }

     $all[] = $array;
}

$all = array_merge(...$all);

?>

1.2.1129.1. Specs

Short name

Performances/SkipEmptyArray

Rulesets

All, Changed Behavior, Performances

Exakat since

2.5.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud