Kim Kim - 4 months ago 8
JSON Question

Get value from JSON array in PHP

I'm trying to get the value from this following JSON array in a PHP variable.

This is a var_dump of the array:

array(3) {
["id"]=>
string(2) "14"
["css"]=>
string(400) ""
["json"]=>
string(4086) "
{
"Canvas": [
{
"MainObjects": {
"After Participation": {
"afterParticipationHeader": "Thank you!"
},
"Invite Friends": {
"InviteHeadline": "",
"InviteMsg": "",
"InviteImg": ""
}
},
"QuizModule": {
"Questions": [],
"Submit_Fields": [
{
"label": "Name",
"name": "txtName",
"value": true
}
]
}
}
]
}"
}


I am able to get the values for ["json"] in PHP like:

$json = $data[0]['json'];


But how do I get the value from from the array inside "json", like "AfterParticipationHeader". And "Submit_Fields" ?

som som
Answer

First you have to decode your json data

$json = json_decode($data[0]['json']);

Then you can access your AfterParticipationHeader

$json->Canvas[0]->MainObjects->{"After Participation"}->afterParticipationHeader
Comments