Are there any best practices for handling nested arrays when decoding JSON in PHP?

When decoding JSON in PHP that contains nested arrays, it is important to properly handle the nested structure to access the data correctly. One common approach is to recursively iterate through the decoded JSON data to handle nested arrays and extract the desired values.

$jsonData = '{
    "name": "John Doe",
    "age": 30,
    "address": {
        "street": "123 Main St",
        "city": "New York",
        "zipcode": "10001"
    }
}';

$data = json_decode($jsonData, true);

function extractNestedData($data) {
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            extractNestedData($value);
        } else {
            echo $key . ': ' . $value . "\n";
        }
    }
}

extractNestedData($data);