What are the advantages and disadvantages of using arrays to store and manipulate data compared to file operations in PHP?

When deciding between using arrays to store and manipulate data or file operations in PHP, it is important to consider the advantages and disadvantages of each approach. Arrays are efficient for storing and accessing data in memory, making them faster for small to medium-sized datasets. However, arrays are limited by memory constraints and may not be suitable for very large datasets. File operations, on the other hand, allow for persistent storage of data but can be slower and more resource-intensive compared to arrays.

// Example of using arrays to store and manipulate data
$data = [
    'John' => 25,
    'Jane' => 30,
    'Alice' => 22
];

// Accessing data from the array
echo $data['John']; // Output: 25

// Adding new data to the array
$data['Bob'] = 28;

// Removing data from the array
unset($data['Jane']);
```

```php
// Example of using file operations to store and manipulate data
// Writing data to a file
$file = fopen('data.txt', 'w');
fwrite($file, "John,25\nJane,30\nAlice,22");
fclose($file);

// Reading data from the file
$file = fopen('data.txt', 'r');
while (($line = fgets($file)) !== false) {
    $data = explode(',', $line);
    echo $data[0] . ' is ' . $data[1] . ' years old' . PHP_EOL;
}
fclose($file);