<?php
$scourses = '{"courses":[
{
"course": "40241",
"lecturer": "gideonk"
},
{
"course": "tau_2021b",
"student": "gideonk"
}
] } ';
$usercourse = 'tau_2021b';
$courses = json_decode($scourses , true);
/* $courses['courses'] is an array of objects
{
"course": "40241",
"lecturer": "gideonk"
}
to access it you will use: $course['course']
$courses['courses'][0]['course'] == 40241
*/
foreach ($courses['courses'] as $course ) {
if ($course['course'] == $usercourse)
echo "Course: ".$course['course']."<br>";
else
echo "------: ".$course['course']."<br>";
}
?>