How can you iterate through object keys in PHP using foreach loop?
To iterate through object keys in PHP using a foreach loop, you can use the get_object_vars() function to retrieve all the properties of the object as an associative array, and then iterate through the keys of this array using a foreach loop.
// Create an object
$obj = new stdClass();
$obj->name = 'John';
$obj->age = 30;
$obj->city = 'New York';
// Get object properties as an associative array
$properties = get_object_vars($obj);
// Iterate through object keys using foreach loop
foreach ($properties as $key => $value) {
echo $key . ': ' . $value . PHP_EOL;
}