$path = 'path/'; $arr = ['img1', 'img2', 'img3']; $i = isset($_COOKIE['img']) ? (int) $_COOKIE['img'] : 0; <img src="<?= $path . $arr[$i] ?>">