I have two multidimensional arrays . An array I am bringing from a .json file , the other is coming from a POST via Ajax .
My idea is to generate a new array by merging these two other multidimensional arrays without repeating the data.
Arrays coming from POST via Ajax bring information from elements of a page. The 'time' field is unique, since the 'vis' field can vary between 0 and 1 (not displayed and displayed).
This is the array coming from the .json file:
{"AdministradorGabrielOliveira":
[
{
"tempo":"2017-08-24T04:57:13-03:00",
"vis":1
},
{
"tempo":"2017-08-24T04:57:13-03:04",
"vis":0
},
{
"tempo":"2017-08-24T04:57:13-03:05",
"vis":0
}
]
}
And below is the array coming from POST via Ajax:
{"AdministradorGabrielOliveira":
[
{
"tempo":"2017-08-24T04:57:13-03:00",
"vis":0
},
{
"tempo":"2017-08-24T04:57:13-03:01",
"vis":0
}
]
}
In the end, I should have as a result of merging the two arrays , another one with the content:
{"AdministradorGabrielOliveira":
[
{
"tempo":"2017-08-24T04:57:13-03:00",
"vis":1
},
{
"tempo":"2017-08-24T04:57:13-03:04",
"vis":0
},
{
"tempo":"2017-08-24T04:57:13-03:05",
"vis":0
},
{
"tempo":"2017-08-24T04:57:13-03:01",
"vis":0
}
]
}
I tried to traverse the arrays within two foreach , but I did not succeed. Can anyone give me a tip?
[EDITED] : I followed your tip and changed the structure for the user to hold the values 'time' and 'vis', with 'time' being or id.