Since you want to avoid duplicates, I assume there are only four images.
You can use shuffle
to randomize a previously created array:
$rands = range(1,4);
shuffle($rands);
foreach( $galleria as $image ):
<figure class="gallery__item--<?= array_pop($rands); ?>">
endforeach;
If you have more than 4 elements you can still use this approach checking if there are elements left and regenerating the array. If you need every iteration to be different you can also check that the ordering hasn't been used before (just keep in mind that there are a limited number of combinations).
$rands = [];
$pasts = [];
foreach( $galleria as $image ):
if (empty($rands)):
do {
$rands = range(1,4);
shuffle($rands);
} while (in_array($rands, $pasts));
$pasts[] = $rands;
endif;
<figure class="gallery__item--<?= array_pop($rands); ?>">
endforeach;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…