Jump to content

JeroenB

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by JeroenB

  1. 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!

×
×
  • Create New...