Skip to content

Commit 67cb560

Browse files
committed
[EH] add $removeNumericIndex option to ShortSyntaxArray
1 parent 1fce4a2 commit 67cb560

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Helper/ShortSyntaxArray.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ShortSyntaxArray
66
{
7-
public static function parse(array $expression, $indent = 4): string
7+
public static function parse(array $expression, $removeNumericIndex = false, $indent = 4): string
88
{
99
$object = json_decode(str_replace(['(', ')'], ['&#40', '&#41'], json_encode($expression)), true);
1010
$export = str_replace(['array (', ')', '&#40', '&#41'], ['[', ']', '(', ')'], var_export($object, true));
@@ -14,6 +14,10 @@ public static function parse(array $expression, $indent = 4): string
1414
$export = preg_replace("/([ ]{2})(?![^ ])/m", $spaces, $export);
1515
$export = preg_replace("/^([ ]{2})/m", $spaces, $export);
1616

17+
if ($removeNumericIndex) {
18+
$export = preg_replace("/([0-9]+) => /m", '', $export);
19+
}
20+
1721
return $export;
1822
}
1923
}

0 commit comments

Comments
 (0)