1.2.277. Could Be array_combine()¶
This rule suggests using the native function array_combine() to merge two arrays into a hash. array_combine() takes the keys and the values from two distinct arrays, and merge them into one.
<?php
$keys = [1, 2, 3];
$values = ['a', 'b', 'c'];
$destination = [];
foreach($keys as $k => $v) {
$destination[$v] = $values[$k];
}
$destination = [1 => 'a', 2 => 'b', 3 => 'c'];
$destination = array_combine($keys, $values);
?>
See also How to use array_merge() and array_combine() in PHP ?.
1.2.277.1. Connex PHP features¶
1.2.277.1.1. Suggestions¶
Use array_combine().
1.2.277.1.2. Specs¶
Short name |
Structures/CouldBeArrayCombine |
Rulesets |
|
Exakat since |
2.5.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |