Is it possible to use different keys for the same value?
[activerecord, activemodel]: 'test'
I expect the same result as with this:
activerecord: 'test' activemodel: 'test'
In YAML, Array represents a single key mapped to multiple values. Each value starts with a hyphen - symbol followed by space. In a single line, write the same thing above using 'square brackets syntax. '
Duplicate keys in YAML files are not allowed in the spec (https://yaml.org/spec/1.2.2/#nodes, https://yaml.org/spec/1.0/#model-node), but the older version of symfony/yaml does not complain about them.
Spaces are allowed in keys according to the specification and for those you don't need quotes (double or single, each with their own use). It is just a scalar string containing a space.
2. Key-Value Pairs. The YAML above defines four keys - first_name , last_name , age_years , and home - with their four respective values. Values can be character strings, numeric (integer, floating point, or scientfic representation), Boolean ( true or false ), or more complex nested types (see below).
That doesn't work because YAML allows you to specify keys of any type, so
[activerecord, activemodel]: 'test'
is a mapping with a single key, the sequence [activerecord, activemodel]
whose value is 'test'
.
Instead, you can use an anchor/alias:
activerecord: &my_value 'test' activemodel: *my_value
However, there's no way of attaching both keys to the single value in one key/value pair.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With