1.2.1138. Slice Arrays First¶
Always start by reducing an array before applying some transformation on it. The shorter array will be processed faster.
The gain produced here is greater with longer arrays, or greater reductions. They may also be used in loops. This is a micro-optimisation when used on short arrays.
<?php
// fast version
$a = array_map('foo', array_slice($array, 2, 5));
// slower version
$a = array_slice(array_map('foo', $array), 2, 5);
?>
1.2.1138.1. Connex PHP features¶
1.2.1138.1.1. Suggestions¶
Use the array transforming function on the result of the array shortening function.
1.2.1138.1.2. Specs¶
Short name |
Arrays/SliceFirst |
Rulesets |
|
Exakat since |
1.0.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |