Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[YAML] Array keys disappeared when dump #18843

Copy link
Copy link
Closed
@flat1701

Description

@flat1701
Issue body actions

I executed like below.

$array = ['foo' => ['bar' => [1 => 2, 'baz' => 3]]];
echo Yaml::dump($array);

I expected

foo:
bar: { 1: 2, baz: 3 }

but result is

foo:
bar: [2, 3]

I edited Yaml/Inline.php like below, I got wanted result.

@@ -159,9 +159,7 @@
     {
         // array
         $keys = array_keys($value);
-        if ((1 == count($keys) && '0' == $keys[0])
-            || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
-        ) {
+        if ($keys === range(0, count($keys)-1)) {
             $output = array();
             foreach ($value as $val) {
                 $output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.