funkyjay
funkyjay

Reputation: 1

Twig set key on multidimensional array

i want to set the keys for an array but have some troubles:

{% set status = [
   {10 : { 'status': 'unchanged',  'color':  'red'}}, 
  {20 : { 'status': 'changed',     'farbe':  'green'}}
 ] %}

gives me:

array(2) { 

    [0]=> array(1) { [10]=> array(2) { ["status"]=> string(9) "unchanged" ["color"]=> string(3) "red" } } 
    [1]=> array(1) { [20]=> array(2) { ["status"]=> string(7) "changed" ["farbe"]=> string(5) "green" } } }

but i want to get:

array(2) { 
    [10]=> array(2) { ["status"]=> string(9) "unchanged" ["color"]=> string(3) "red" } 
    [20]=> array(2) { ["status"]=> string(7) "changed" ["farbe"]=> string(5) "green" } }

Is there a way to achieve this?

Upvotes: 0

Views: 1104

Answers (1)

DarkBee
DarkBee

Reputation: 15582

{% set status = { 10 : { .... }, 20 : { ..... }, } %}

Upvotes: 1

Related Questions