First of all, the name attribute is deprecated in favour of id. Since you already have the id attribute you might as well just drop the name.
Secondly: PHP doesn't know anything about your HTML - it's just a big lump of text that it sent out to the browser at some time in the past and then forgot about - so it doesn't know anything about any tag's attributes.
But assuming that in your PHP script you have a variable $image in which you have the name/id of the image you want displayed:
echo '<td>';
switch($image)
{
case 'img1': $id = 'img1'; $src = '/img1.jpg'; break;
case 'img2': $id = 'img2'; $src = '/img2.jpg'; break;
// ....
}
echo "<img id='$id' src='$src' />";
echo '</td>';
For the examples given there's some redundancy that suggests further simplifications may be possible.