user2143356
user2143356

Reputation: 5607

Parameters as array in Yaml in Symfony2

I'm doing this which works fine:

parameters:
 array_name1: [a, b, c, d]
 array_name2: [x, y, a, b]

Now I need to add what in PHP would be $array_name3[1] = array("a", "b", "c") etc., so something like this:

parameters:
 array_name3[1]: [1, 2, 3]
 array_name3[2]: [a, b, c]
 array_name3[3]: [x, y, z]

...which of course doesn't work. Nothing I try seems to be accepted.

How do I define multi-dimensional arrays in Yaml (Symfony2)?

Upvotes: 33

Views: 42050

Answers (1)

Vitalii Zurian
Vitalii Zurian

Reputation: 17986

Try this

parameters:
   array_name3: 
      - [1, 2, 3]
      - [a, b, c]
      - [x, y, z]

Or if you want to have it associative:

parameters:
   array_name3: 
      1: [1, 2, 3]
      2: [a, b, c]
      bla: [x, y, z]

Or if you want more - read documentation

Upvotes: 58

Related Questions