Skip to content

Commit 72c53d9

Browse files
committed
show() supports arg names
1 parent 15b6a33 commit 72c53d9

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

packages/utilities/src/Arr.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,14 +1210,16 @@ public static function show(...$args): void
12101210

12111211
$level = 5;
12121212

1213-
if (count($args) > 1) {
1214-
$last = array_pop($args);
1213+
if (array_is_list($args) && count($args) > 1) {
1214+
$last = $args[array_key_last($args)];
12151215

12161216
if (is_int($last)) {
12171217
$level = $last;
1218-
} else {
1219-
$args[] = $last;
1218+
array_pop($args);
12201219
}
1220+
} elseif (array_key_last($args) === 'deep' && is_int($args['deep'])) {
1221+
$level = $args['deep'];
1222+
unset($args['deep']);
12211223
}
12221224

12231225
fwrite($output, "\n\n");
@@ -1227,14 +1229,17 @@ public static function show(...$args): void
12271229
}
12281230

12291231
// Dump Multiple values
1230-
if (count($args) > 1) {
1232+
if (count($args) > 1 || !array_is_list($args)) {
12311233
$prints = [];
12321234

1233-
$i = 1;
1235+
foreach ($args as $i => $arg) {
1236+
if (is_int($i)) {
1237+
$scope = sprintf("[Value %s]", $i + 1);
1238+
} else {
1239+
$scope = "[$i]";
1240+
}
12341241

1235-
foreach ($args as $arg) {
1236-
$prints[] = '[Value ' . $i . "]\n" . $dumper($arg, $level);
1237-
$i++;
1242+
$prints[] = $scope . "\n" . $dumper($arg, $level);
12381243
}
12391244

12401245
fwrite($output, implode("\n\n", $prints));

0 commit comments

Comments
 (0)