What are potential pitfalls to be aware of when trying to access specific values from arrays in PHP for learning purposes?

When trying to access specific values from arrays in PHP, potential pitfalls to be aware of include using incorrect array keys or indices, not checking if the key or index exists before accessing it, and not handling errors or warnings that may arise from accessing non-existent keys or indices.

// Example of accessing specific values from an array safely
$array = ['key1' => 'value1', 'key2' => 'value2'];

// Check if the key exists before accessing it
if (array_key_exists('key1', $array)) {
    $value = $array['key1'];
    echo $value;
} else {
    echo 'Key does not exist';
}