Ciao a tutti,
ho un problema con un carousel, teoricamente dovrei, attraverso 4 button, caricare 4 array di immagini diversi.

ho impostato il bottone in questo modo

<div class="carousel-inner" role="">
<?php foreach ($car->images as $i => $image): ?>
<div class="item <?php if (!$i): ?> active <?php endif ?>">
<img src="<?= $image ?>" class="img-responsive js-carousel" data-index="<?= $i ?>"
alt="<?= $car->title ?>" id="myCarousel2">
</div>
<div class="ts-degree-views-icon">
<div class="hidden-xs hidden-sm visible-md visible-lg">
<div class="btn-group">
<button value="esterno" onclick="esterni()">
<img src="/assets/images/gallery-icon/esterni-icon-text.svg" alt="">
</button>
<button value="interno" onclick="interni()">
<img src="/assets/images/gallery-icon/interni-icon-text.svg" alt="">
</button>
<button value="motore" onclick="motore()">


<img src="/assets/images/gallery-icon/motore-icon-text.svg" alt="">
</button>
<button value="difetti" onclick="difetti()">
<img src="/assets/images/gallery-icon/difetti-icon-text.svg" alt="">
</button>
</div>
</div>




ed ho scritto questa funzione


</div>
<?php endforeach ?>
<script>


function esterni() {
var im=document.getElementById("myCarousel2");
var images1 = new Array("<?= join('","', $car->esternoimg)?>");
for (var i=0; i<=images1.length; i++){
im.src = images1[i];
document.getElementById("myCarousel2").innerHTML = im.src ;
}
}


function interni(){
var im=document.getElementById("myCarousel2");
var images2 = new Array("<?= join('","', $car->internoimg)?>");
for (var i=0; i<=images2.length; i++){
im.src = images2[i];
}

}


function motore(){
var im=document.getElementById("myCarousel2");
var images3 = new Array("<?= join('","', $car->motoreimg)?>");
for(var i=0; i<=images3.length; i++){
im.src =images3[i];
}
}


function difetti(){
var im=document.getElementById("myCarousel2");
var images4 = new Array("<?= join('","', $car->danni)?>");
for (var i = 0 ; i >= images4.length; i++) {
im.src = images4[i];
document.getElementById("myCarousel2").innerHTML = im.src ;
}
}

</script>

Grazie mille per l'aiuto