Let's say I have a JSON object like this:
{
"result": [{
"questionId": "1",
"sectionId": "1",
"questionText": "Foo bar blah blah",
"questionType": "R"
}, {
"questionId": "2",
"sectionId": "1",
"questionText": "qoox foo",
"questionType": "R"
}, {
"questionId": "3",
"sectionId": "2",
"questionText": "Hello world",
"questionType": "D"
}, {
"questionId": "4",
"sectionId": "2",
"questionText": "asdasdasd",
"questionType": "R"
}, {
"questionId": "5",
"sectionId": "3",
"questionText": "to be or not to be",
"questionType": "D"
}]
}
As you can see, there are 3 sectionId
s, so I'd like to rearrange that based on the sectionId
, something like this:
{
"result": [{
"1": {
"questionId": "1",
"questionText": "Foo....",
"questionType": "R"
}
}
},
{
"2": .....
},
{
"3": ....
}]
}
My PHP knowledge is pretty limited. How can I do this?