Something like this might work.
<script type="text/javascript">
//Example error handling
var imgPlaceHolder = '//example.com/no-img.jpg';
var handelImageNotFound = function (imgId) {
$('#' + imgId).attr("src", imgPlaceHolder);
}
</script>
<?php
$imgList = [
'//example.com/foo1.jpg',
'//example.com/foo2.jpg',
'//example.com/baz.jpg',
];
?>
<?php for ($index = 0; $index < count($imgList); $index++): ?>
<img src="<?= $imgList[$index] ?>" id="img_<?= $index ?>" onerror="handelImageNotFound('img_<?= $index ?>')" />
<?php endfor; ?>
Now you will have to write a javascript method "handelImageNotFound(imgId)
" function to handle missing images.