What are the advantages of using a structured interface for classes in PHP, and how can it enhance code reusability and flexibility?

Using a structured interface for classes in PHP allows for a clear definition of the methods that a class must implement. This enhances code reusability by promoting a consistent API across different classes that implement the same interface. It also increases flexibility as classes can be easily swapped out as long as they adhere to the interface contract.

<?php

interface LoggerInterface {
    public function log($message);
}

class FileLogger implements LoggerInterface {
    public function log($message) {
        // Log message to a file
    }
}

class DatabaseLogger implements LoggerInterface {
    public function log($message) {
        // Log message to a database
    }
}