lundi 30 décembre 2019

how to marge 2 array based on value?

I have 2 arrays, in this case, I want to combine the two arrays into one. Here I have 2 arrays namely remarks and remark_asset

here are the array of remarks

[
  {
    "id": 5,
    "type": "Text",
    "name": "Text",
    "label": "Txt L",
    "description": "Txt D",
    "filter_logic": null,
    "default": "Txt Def",
    "weight": "12",
    "required": "true",
    "created_at": "2019-12-10 18:20:37",
    "updated_at": "2019-12-10 18:20:37"
  },
  {
    "id": 6,
    "type": "Date",
    "name": "Date",
    "label": "Date Label",
    "description": "Date DEsc",
    "filter_logic": null,
    "default": "2019-12-10",
    "weight": "12",
    "required": "false",
    "created_at": "2019-12-10 18:30:29",
    "updated_at": "2019-12-10 18:30:29"
  },
  {
    "id": 7,
    "type": "Checkbox",
    "name": "Kotaro",
    "label": "Cex",
    "description": "cex desc",
    "filter_logic": null,
    "default": "true",
    "weight": "11",
    "required": "false",
    "created_at": "2019-12-10 18:32:13",
    "updated_at": "2019-12-10 18:32:13"
  },
  {
    "id": 13,
    "type": "List",
    "name": null,
    "label": "Label",
    "description": "Desc",
    "filter_logic": null,
    "default": "1,2,3,4",
    "weight": null,
    "required": "false",
    "created_at": "2019-12-30 01:46:44",
    "updated_at": "2019-12-30 01:46:44"
  }
]

and this is an array of remark assets

[
  [
    {
      "id": 210,
      "asset_id": 94092,
      "remark_id": 5,
      "value": "Txt Def",
      "created_at": "2019-12-13 08:55:41",
      "updated_at": "2019-12-13 08:55:41"
    },
    {
      "id": 211,
      "asset_id": 94092,
      "remark_id": 6,
      "value": "2019-12-10",
      "created_at": "2019-12-13 08:55:41",
      "updated_at": "2019-12-13 08:55:41"
    },
    {
      "id": 212,
      "asset_id": 94092,
      "remark_id": 7,
      "value": "true",
      "created_at": "2019-12-13 08:55:41",
      "updated_at": "2019-12-13 08:55:41"
    }
  ],
  [
    {
      "id": 213,
      "asset_id": 94093,
      "remark_id": 5,
      "value": "Txt Def",
      "created_at": "2019-12-13 09:00:16",
      "updated_at": "2019-12-13 09:00:16"
    },
    {
      "id": 214,
      "asset_id": 94093,
      "remark_id": 6,
      "value": "2019-12-10",
      "created_at": "2019-12-13 09:00:16",
      "updated_at": "2019-12-13 09:00:16"
    },
    {
      "id": 215,
      "asset_id": 94093,
      "remark_id": 7,
      "value": "true",
      "created_at": "2019-12-13 09:00:16",
      "updated_at": "2019-12-13 09:00:16"
    }
  ]
]

and my expectation value is like this

[
 {
    "Txt L": "Txt Def",
    "Date Label": "2019-12-10",
    "Cex": "true",
    "Label": null
  }
]

so I will explain about my question, so in the array that I want the key of the array is the label of the remax array, then the value of the key is the data of the value contained in the said asset, so the key displayed will be dynamic, here I have take out each array, now how do I make it possible to join the two arrays? So the value part must match the id remark, for example "Txt L": the value is data that has the same id as "Txt L":



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2szisHZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire