In PHP, what are the advantages of storing array data in a database or CSV format instead of directly in a file?

Storing array data in a database or CSV format allows for easier retrieval, searching, and manipulation of the data compared to storing it directly in a file. Databases provide structured storage with query capabilities, while CSV files offer a standardized format for exchanging data with other systems. Both methods offer better scalability and organization for managing large datasets.

// Example of storing array data in a CSV file
$data = array(
    array('John', 'Doe', 'john.doe@example.com'),
    array('Jane', 'Smith', 'jane.smith@example.com')
);

$fp = fopen('data.csv', 'w');
foreach ($data as $fields) {
    fputcsv($fp, $fields);
}
fclose($fp);