I am trying to decode a JSON string into an array but i get the following error.
Fatal error: Cannot use object of type stdClass as array in C:\\w
I hope this will help you
$json_ps = '{"courseList":[
{"course":"1", "course_data1":"Computer Systems(Networks)"},
{"course":"2", "course_data2":"Audio and Music Technology"},
{"course":"3", "course_data3":"MBA Digital Marketing"}
]}';
Use Json decode function
$json_pss = json_decode($json_ps, true);
Looping over JSON array in php
foreach($json_pss['courseList'] as $pss_json)
{
echo '
' .$course_data1 = $pss_json['course_data1']; exit;
}
Result: Computer Systems(Networks)