This is the code, it use a foreach to access to department and workers .
EDIT: Will correct several paste errors
<?php
$json = '{
"boss": "Jeff",
"department": [{
"office": "1111",
"workers": "[{\"id_work\":\"123\",\"name\":\"mike\",\"mobile\":\"12345\"}]"
}]}';
$json_data = json_decode($json);
echo "Boss:".$json_data->boss;
echo "<br>";
foreach($json_data->deparment as $dep)
{
echo "Office number:".$dep->office."<br>";
foreach($dep->workers as $worker){
echo "Worker ID: ".$worker->id_work."<br>";
echo "Worker name : ".$worker->name."<br>";
echo "Worker mobil: ".$worker->mobil."<br>";
}
}
?>
I cannot access to internal array when I try do a foreach() this happens :
Invalid argument supplied for foreach()
How I can access to the information of the nested array
]at the end ->}]}.json_decode()to force an array result and it does not look like OP requires itworkersproperty is a string, not an array. Looks like you've double-encoded it. Tryforeach(json_decode($dep->workers) as $worker)or you know, fix your data formattrueas the second parameter injson_decode()to convert your json to normal php array. easy to handle (for me both are easy to handle)