How can foreach be effectively used in PHP to iterate through JSON data obtained from an API?

When iterating through JSON data obtained from an API in PHP, you can use the `json_decode()` function to convert the JSON data into an associative array. Then, you can use a `foreach` loop to iterate through the array and access the data. This allows you to easily extract and manipulate the data returned from the API.

// JSON data obtained from API
$json_data = '{
    "name": "John Doe",
    "age": 30,
    "email": "john.doe@example.com"
}';

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

// Iterate through the array using foreach
foreach ($data as $key => $value) {
    echo $key . ': ' . $value . '<br>';
}