What potential pitfalls should be considered when working with arrays and echoing values in PHP?

One potential pitfall when working with arrays and echoing values in PHP is not checking if the array key exists before trying to access it. This can lead to "Undefined index" errors if the key does not exist in the array. To avoid this issue, you can use the isset() function to check if the key exists before echoing its value.

// Check if the array key exists before echoing its value
if(isset($array['key'])) {
    echo $array['key'];
} else {
    echo 'Key does not exist';
}