I tried and was able to print out the whole JSON file as string using this piece of code:
$str_data = file_get_contents("DB/TEITC502_OS.json");
$data = json_decode($str_data,true);
echo $str_data[0];
The JSON file with the following structure:
[
{
"id": 1,
"name": "Overview of Operating system",
"hours": 4,
"sm": [
{
"smid": 1.1,
"smn": "Overview of Operating system objectives and functions"
},
{
"smid": 1.2,
"smn": "Evolution of OS"
}
]
},
{
"id": 2,
"name": "Process Management",
"hours": 10,
"sm": [
{
"smid": 2.1,
"smn": "Process"
},
{
"smid": 2.2,
"smn": "Process States"
},
{
"smid": 2.3,
"smn": "Process Control Block (PCB)"
}
]
}
]
However I want to print out each of these details(id,name,hours,smid,smn) individually using PHP.
What changes should I make to the echo
statement in-order to accomplish this?