1.2.293. Could Use Compact¶
Compact() turns a group of variables into an array. It may be used to simplify expressions. Note that compact accepts any string, and any undefined variable is not set, without a warning.
<?php
$a = 1;
$b = 2;
// Compact call
$array = compact('a', 'b');
$array === [1, 2];
// Detailing all the keys and their value
$array = ['a' => $a, 'b' => $b];
?>
See also compact.
1.2.293.1. Connex PHP features¶
1.2.293.1.1. Suggestions¶
Replace the array() call with a compact() call.
1.2.293.1.2. Specs¶
Short name |
Structures/CouldUseCompact |
Rulesets |
|
Exakat since |
1.1.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |