1.2.1309. Use Array Functions

There are a lot of native PHP functions for arrays. It is often faster to take advantage of them than write a loop.

<?php

$all = implode('-', $s).'-';

// same as above
$all = '';
foreach($array as $s) {
    $all .= $s . '-';
}

?>

See also Array Functions and No array_merge() In Loops.

1.2.1309.1. Suggestions

  • Remove the loop and use a native PHP function

  • Add more expressions to the loop : batching multiple operations in one loop makes it more interesting than running separates loops.

1.2.1309.2. Specs

Short name

Structures/UseArrayFunctions

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.8.8

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

class

Available in

Entreprise Edition, Exakat Cloud