What are common pitfalls to avoid when working with arrays and file handling in PHP?

One common pitfall when working with arrays and file handling in PHP is not properly checking if a file exists before trying to read from or write to it. This can result in errors or unexpected behavior if the file is not found. To avoid this, always use functions like `file_exists()` or `is_file()` to check if the file exists before performing any operations on it.

$file_path = 'example.txt';

if (file_exists($file_path)) {
    // Read from or write to the file
    $file_contents = file_get_contents($file_path);
    // Perform operations on $file_contents
} else {
    echo "File does not exist.";
}