From 1743655b63e048c283f90a5fa7e535f5591706b7 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sat, 24 Dec 2022 17:49:27 +0100 Subject: [PATCH] [Yaml] Add flag to dump numeric key as string --- components/yaml.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/yaml.rst b/components/yaml.rst index 2c463d1c731..e20427069d7 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -418,6 +418,22 @@ you can dump them as ``~`` with the ``DUMP_NULL_AS_TILDE`` flag:: $dumped = Yaml::dump(['foo' => null], 2, 4, Yaml::DUMP_NULL_AS_TILDE); // foo: ~ +Dumping Numeric Keys as Strings +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By default, digit-only array keys are dumped as integers. You can use the +``DUMP_NUMERIC_KEY_AS_STRING`` flag if you want to dump string-only keys:: + + $dumped = Yaml::dump([200 => 'foo']); + // 200: foo + + $dumped = Yaml::dump([200 => 'foo'], 2, 4, Yaml::DUMP_NUMERIC_KEY_AS_STRING); + // '200': foo + +.. versionadded:: 6.3 + + The ``DUMP_NUMERIC_KEY_AS_STRING`` flag was introduced in Symfony 6.3. + Syntax Validation ~~~~~~~~~~~~~~~~~