When i assign a key value into an array of type string, does it have to be in quotes?
define('ALBUM_COVER_50', '../discography/artwork/cover/50/');
define('ALBUM_COVER_ZOOM', '../discography/artwork/cover/800/');
$selected_artwork = array();
$cover = 'greatesthits_cs23409.jpg';
$selected_artwork[ALBUM_COVER_50.$cover] = ALBUM_COVER_ZOOM.$cover;
In the above snippet, do i have to put ALBUM_COVER_50.$cover in quotes like:
$selected_artwork['\''.ALBUM_COVER_50.$cover.'\''] = ALBUM_COVER_ZOOM.$cover;
What is the best practice to go about this issue?
No, it does not need to be in quotes if you use a variable or defined constant as the array key. You should think of the key you use as a string value itself. PHP will process it as it does any other string value, which means you can use variables, double-quoted variable interpolation, concatenation, or anything you need to construct an array key.
If it improves readability, I will often store the needed array key into a variable. Recently I needed to do this because the array key was the result of 3 or 4 string concatenations and it was unwieldy to read.