What are the potential pitfalls of storing image names in a string separated by commas in PHP?

Storing image names in a string separated by commas can make it difficult to retrieve and manipulate individual image names. It can also lead to errors when trying to add or remove images from the list. To solve this issue, consider storing image names in an array instead of a string.

// Storing image names in an array
$images = ['image1.jpg', 'image2.jpg', 'image3.jpg'];

// Adding a new image to the array
$newImage = 'image4.jpg';
$images[] = $newImage;

// Removing an image from the array
$removeImage = 'image2.jpg';
$key = array_search($removeImage, $images);
if ($key !== false) {
    unset($images[$key]);
}

// Retrieving individual image names from the array
foreach ($images as $image) {
    echo $image . '<br>';
}