foreach ($colors as $item):?>
<img rel="<?=$item['id']?>" src="/<?=$item['image_path']?>" class="" />
<?php
foreach ($colors as $key => $item){
$tmp = "<img rel=\"%s\" src=\"/%s\" class=\"%s\" />";
$class = (($key <= 2) ? "classname", "");
printf($tmp, $item['id'], $item['image_path'], $class);
}
?>
<? foreach ($colors as $i => $item): ?>
<img rel="<?=$item['id']?>" src="/<?=$item['image_path']?>" class="class<?=($i < 3)?>" />
<? endforeach ?>