I have an array like this:
array
0 =>
array (size=5)
'id' => string '1' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'info@test.de' (length=16)
1 =>
array (size=5)
'id' => string '3' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'kun@test.de' (length=26)
2 =>
array (size=5)
'id' => string '5' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'ni@test.de' (length=23)
3 =>
array (size=5)
'id' => string '410' (length=3)
'hostings_id' => string '5' (length=1)
'email' => string 'spam@email.de' (length=13)
4 =>
array (size=5)
'id' => string '148' (length=3)
'hostings_id' => string '5' (length=1)
'email' => string 'e@email.de' (length=23)
5 =>
array (size=5)
'id' => string '165' (length=3)
'hostings_id' => string '8' (length=1)
'email' => string 'mobil@newmail.de' (length=15)
6 =>
...
My goal is to put this array into a new array:
array
0 =>
array (size=5)
'id' => string '1' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'info@test.de' (length=16)
array (size=5)
'id' => string '3' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'kun@test.de' (length=26)
array (size=5)
'id' => string '5' (length=1)
'hostings_id' => string '4' (length=1)
'email' => string 'ni@test.de' (length=23)
1 =>
array (size=5)
'id' => string '410' (length=3)
'hostings_id' => string '5' (length=1)
'email' => string 'spam@email.de' (length=13)
array (size=5)
'id' => string '148' (length=3)
'hostings_id' => string '5' (length=1)
'email' => string 'e@email.de' (length=23)
2 =>
array (size=5)
'id' => string '165' (length=3)
'hostings_id' => string '8' (length=1)
'email' => string 'mobil@newmail.de' (length=15)
3 =>
At the end I want an JSON like this:
{
"emails": {
"0": {
"id": "1",
"hostings_id": "4",
"email": "info@test.de",
},
"1": {
"id": "3",
"hostings_id": "4",
"email": "kun@test.de",
},
"2": {
"id": "5",
"hostings_id": "4",
"email": "ni@test.de",
},
}
}
{
"emails": {
"0": {
"id": "410",
"hostings_id": "5",
"email": "spam@email.de",
},
"0": {
"id": "148",
"hostings_id": "5",
"email": "e@email.de",
},
}
}
...
I want to create the JSON based on the 'hostings_id' Everything what has the same 'hostings_id' value should be together in a separated JSON.
I´ve tried a lot with foreach and array_count_values but did not get the result I want. Thank you very much for you help.
regards