What are common methods for handling nested objects within arrays in PHP?

When dealing with nested objects within arrays in PHP, a common method is to use nested loops to iterate through the array and access the nested objects. This allows you to access and manipulate the data within the nested objects effectively.

// Example array with nested objects
$data = [
    [
        'name' => 'John',
        'age' => 30,
        'address' => [
            'street' => '123 Main St',
            'city' => 'New York'
        ]
    ],
    [
        'name' => 'Jane',
        'age' => 25,
        'address' => [
            'street' => '456 Elm St',
            'city' => 'Los Angeles'
        ]
    ]
];

// Loop through the array and access nested objects
foreach ($data as $person) {
    echo $person['name'] . ' lives at ' . $person['address']['street'] . ' in ' . $person['address']['city'] . PHP_EOL;
}