1.2.1318. 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 . '-';
}

// extract one index in an array
$extract = [];
foreach($array as $a) {
     $extract[] = $a['index'];
}

$extract = array_column($array, 'index');

?>

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

1.2.1318.1. Connex PHP features

1.2.1318.1.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.1318.1.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

Available in

Entreprise Edition, Exakat Cloud