1.2.1115. Should Use Explode Args¶
explode() has a third argument, which limits the amount of exploded elements. With it, it is possible to collect only the first elements, or drop the last ones.
<?php
$exploded = explode(DELIMITER, $string);
// use explode(DELIMITER, $string, -1);
array_pop($exploded);
// use explode(DELIMITER, $string, -2);
$c = array_slice($exploded, 0, -2);
// with explode()'s third argument :
list($a, $b) = explode(DELIMITER, $string, 2);
// with list() omitted arguments
list($a, $b, ) = explode(DELIMITER, $string);
?>
See also explode.
1.2.1115.1. Suggestions¶
Add the third argument to the explode() call
1.2.1115.2. Specs¶
Short name |
Structures/ShouldUseExplodeArgs |
Rulesets |
|
Exakat since |
1.9.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |