How can PHP be used to dynamically generate image file paths based on a variable?

To dynamically generate image file paths based on a variable in PHP, you can concatenate the variable with the base path of the image directory. This allows you to easily generate different image paths based on the value of the variable.

// Variable containing the image file name
$imageName = "example.jpg";

// Base path of the image directory
$imageDirectory = "images/";

// Concatenate the variable with the base path to generate the full image path
$imagePath = $imageDirectory . $imageName;

// Output the dynamically generated image path
echo $imagePath;