How can implementing ArrayAccess improve the functionality of a CSV filtering class in PHP?

Implementing ArrayAccess in a CSV filtering class in PHP allows for treating the object as an array, making it easier to access and manipulate data within the CSV file. This makes the code more intuitive and easier to work with, as developers can use array syntax to interact with the CSV data.

class CSVFilter implements ArrayAccess
{
    private $data = [];

    public function offsetExists($offset)
    {
        return isset($this->data[$offset]);
    }

    public function offsetGet($offset)
    {
        return $this->data[$offset];
    }

    public function offsetSet($offset, $value)
    {
        $this->data[$offset] = $value;
    }

    public function offsetUnset($offset)
    {
        unset($this->data[$offset]);
    }

    // Additional methods for filtering CSV data can be added here
}

// Example usage
$filter = new CSVFilter();
$filter[0] = ['Name', 'Age', 'City'];
$filter[1] = ['John', 25, 'New York'];

echo $filter[1][0]; // Output: John