What are the best practices for efficiently managing dynamic image selection in PHP?

When managing dynamic image selection in PHP, it is important to efficiently handle the selection of images based on certain criteria such as user input or database values. One way to achieve this is by using an array to store the file paths of the images and selecting the appropriate image based on the criteria provided.

// Array of image file paths
$images = [
    'image1.jpg',
    'image2.jpg',
    'image3.jpg'
];

// Criteria for selecting image (for example, user input or database value)
$criteria = 'criteria_value';

// Select image based on criteria
if ($criteria == 'criteria_value') {
    $selected_image = $images[0];
} elseif ($criteria == 'another_criteria_value') {
    $selected_image = $images[1];
} else {
    $selected_image = $images[2];
}

// Display selected image
echo '<img src="' . $selected_image . '" alt="Selected Image">';