How can PHP code be structured to access nested arrays like 'creators' in JSON data?

To access nested arrays like 'creators' in JSON data using PHP, you can decode the JSON data into an associative array and then access the nested array using the appropriate keys.

// JSON data containing nested arrays
$jsonData = '{"title": "Sample Title", "creators": [{"name": "John Doe", "role": "Author"}, {"name": "Jane Smith", "role": "Illustrator"}]}';

// Decode JSON data into an associative array
$data = json_decode($jsonData, true);

// Access the 'creators' array
$creators = $data['creators'];

// Loop through the 'creators' array
foreach($creators as $creator){
    echo $creator['name'] . ' - ' . $creator['role'] . '<br>';
}