What are the advantages and disadvantages of using JavaScript versus PHP to change images dynamically on a webpage?

When changing images dynamically on a webpage, using JavaScript allows for a more interactive and seamless user experience without the need to reload the entire page. However, PHP can also be used to change images dynamically by generating HTML content on the server-side before sending it to the client.

<?php
$image = "new_image.jpg";
echo "<img src='$image' alt='Dynamic Image'>";
?>