I have some code that looks for a branch of a JSON string called applications and then for each item it finds, it executes some code.
This works fine if the JSON contains "applications" but falls over if it doesn't.
My PHP
$json = file_get_contents("programs.json");
$array = json_decode($json, true);
foreach ($array['applications'] as $app) {
$application = $app['application'];
// Do some stuff
}
My JSON looks like this:
{
"hostname": "MINIPC025",
"applications": [{
"application": "7-Zip 19.00 (x64)"
},
{
"application": "Active Directory Rights Management Services Client 2.1"
},
{
"application": "Adobe Acrobat Reader DC MUI"
}
]
}
So my question is - is it possible to put some kind of if statement that says only loop through the applications bit of the JSON data if the applications
property exists.
Thank you.