What are some best practices for accessing nested objects within JSON data when displaying it in an HTML table using PHP?

When accessing nested objects within JSON data to display in an HTML table using PHP, it's important to properly navigate through the nested structure to extract the desired values. One approach is to use nested loops or recursive functions to traverse the JSON data and access the nested objects. By properly handling the nested structure, you can accurately display the data in an organized manner within an HTML table.

<?php
// Sample JSON data
$json_data = '{
    "name": "John Doe",
    "age": 30,
    "address": {
        "street": "123 Main St",
        "city": "New York",
        "zipcode": "10001"
    }
}';

// Decode the JSON data
$data = json_decode($json_data);

// Accessing nested objects within JSON data
echo '<table>';
foreach ($data as $key => $value) {
    if (is_array($value)) {
        foreach ($value as $subKey => $subValue) {
            echo '<tr><td>' . $subKey . '</td><td>' . $subValue . '</td></tr>';
        }
    } else {
        echo '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
    }
}
echo '</table>';
?>