JeroenB Posted July 8, 2016 Share Posted July 8, 2016 I'm having trouble matching/merging two arrays in Twig. Let's say I have an array "tests" and an array "results". Both arrays contain a value "link_id". Now I want to merge the values of the arrays where both the ID's match. For example these two arrays: { "tests": [ { "link_id": "54234", "value1": "test bla" }, { "link_id": "98737", "value1": "bye bye" } ] } { "results": [ { "link_id": "54234", "valueX": "test bla", "valueY": "blabla" }, { "link_id": "98737", "valueX": "bye bye", "valueY": "hello" } ] } and I want to achieve this: { "newdata": [ { "link_id": "54234", "valueX": "test bla", "valueY": "blabla" "value1": "test bla" }, { "link_id": "98737", "valueX": "bye bye", "valueY": "hello" "value1": "bye bye" } ] } So 'tests' and 'results' are merged where there's a matching link_id. How can I do this in Twig? Please let me know! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2016 Share Posted July 8, 2016 I don't know about Twig specifically, but in PHP in general there's not much you can do with that structure other than looping through and finding the matching entries. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now