At first – do not use extract
. It’s very bad code style and is also depracated in core.
Every time your foreach loop run, you override content of $output
because you assign to this variable new content. What you want is to concatenate new list item with existing ones. This can be done using concatening assignment operator:
$output .= '<li class="text-center"> <img src="' . $carouselimage['url'] . '" title="' . $carouselimage['title'] . '" alt="' . $carouselimage['alt'] . '" /></li>';
$output
variable should be defined before your foreach
statement. Just assign to it an empty string.