How can arrays be used to navigate JSON data with complex structures in PHP?

When dealing with JSON data with complex structures in PHP, arrays can be used to navigate through the data by accessing nested keys and values. By converting the JSON data into an associative array using json_decode(), we can easily traverse the structure using array keys. This allows us to access specific data points within the JSON structure and manipulate them as needed.

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

// Convert JSON data to associative array
$dataArray = json_decode($jsonData, true);

// Accessing nested data using array keys
echo $dataArray['name']; // Output: John Doe
echo $dataArray['address']['city']; // Output: New York