What are the best practices for iterating through JSON data using foreach() loop in PHP?

When iterating through JSON data using a foreach() loop in PHP, it is important to first decode the JSON string into an associative array using json_decode(). Then, you can loop through the array using foreach() to access and process each key-value pair.

$jsonData = '{"key1": "value1", "key2": "value2", "key3": "value3"}';
$dataArray = json_decode($jsonData, true);

foreach ($dataArray as $key => $value) {
    echo "Key: " . $key . ", Value: " . $value . "\n";
}