How can you properly escape the $ symbol in PHP when accessing an array element?

When accessing an array element in PHP, the $ symbol is used to denote a variable. If you need to access an array element that has a $ symbol in its key, you can properly escape the $ symbol by using single quotes around the key. This prevents PHP from interpreting the $ symbol as the start of a variable name.

$array = ['$key' => 'value'];
$value = $array['$key']; // Accessing the array element with $key properly escaped
echo $value; // Output: value