0

I'm using symfony2 and twig in my view. I'm sending an array to the view which has been created using from a mysql query, not using the symfony entity framework: $claims_summary_table = $statement->fetchAll();

I can dump this in the view...

{{ dump(claims_summary_table) }}
array:1 [▼
         0 => array:11 [▼
                         "claim_status" => "Open"
                         "claim_id" => "101"
                         "claim_reference" => "BALLINGM"
                         "loss_date_from" => "2015-06-02"
                         "loss_catastrophe_name" => "Fire"
                         "loss_value" => "2000.00"
                         "total_payments" => "300.00"
                         "total_reserve" => "2000.00"
                         "claim_file_closed" => null
                         "last_seen_date" => "2016-04-20 11:20:25"
                         "last_seen_by" => "2"
                         ]
                         ]

but I just want to access one element, I just want to access "Open".

I have tried {{ claims_summary_table.claim_status }}

The only way I can access the single element is if I use a { for.....}.

How can I just get one element?

2
  • can you access the array by position or you need to find a record with the particolar value inside? Commented Apr 20, 2016 at 15:40
  • I need to access the values for "claim_status" and "claim_id". Commented Apr 20, 2016 at 15:48

2 Answers 2

2

If you need to access the first element of the sub-array you can use the following.

{{ claims_summary_table[0][0]. claim_status }}

and

{{ claims_summary_table[0][0]. claim_id }}

Otherwise you need to iterate and looking for the record with the claim_stauts open

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. Why have you suggested [0][0] and @otto suggested [0]?
Hi @user1077250 in the dump of the claims_summary_table variable we see an array of array. The first contain only one element, and the second 11 element (but we want to access only to the first element).
0

You can access the values by array key, in your case:

{{ claims_summary_table[0]. claim_status }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.