I have a sample
$image_src = array(
'image1.jpg', //Yes
'image2.jpg', //This image is 404
'image3.jpg' //Yes
);
for($i=0; $i<count($image_src); $i++) {
if(!file_exists($image_src[$i])) {
$image_src[$i] = 'image_change.jpg';
}
}
print_r($image_src);
But when run result show all image_change.jpg
[0] => 'image_change.jpg',
[1] => 'image_change.jpg',
[2] => 'image_change.jpg'
Result exactly is:
[0] => 'image1.jpg',
[1] => 'image_change.jpg',
[2] => 'image3.jpg'
=>How to fix it
The file name must be the complete path of the file, make sure you set the base directory of the files before calling.