1.2.309. Count() To Array Append

The array append operator is able to generate a sane index, without relying on the count() function. This is faster, and safer.

<?php

$newArray  = [];
foreach($array as $value) {
     // count is overkill here
     $newArray[count($newArray)] = $value;
}

?>

1.2.309.1. Suggestions

  • Remove the call to count()

1.2.309.2. Specs

Short name

Performances/CountToAppend

Rulesets

All, Changed Behavior, Performances

Exakat since

2.6.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Features

append

Available in

Entreprise Edition, Exakat Cloud