If the array has a sequenced index you can use either a modulo calculation or a bitwise operation. If the array is based of non-numeric or not sequenced numbers you need to add a counter.
$i & 1 // odd using bitwise
$i % 2 // odd modulo
So what you would get is the following:
$i = 0;
foreach ($rel as $r) { // note that I have used curly brackets. I think it is cleaner more standard
$i++;
$classes = array('related-item');
if ($i % 2 == 0) $classes[] = 'right';
echo '<div class="'.implode(' ', $classes).'"><a href='.get_permalink($r->ID).'>'.'<div class=page-related-title>'.$r->post_title.'</div>'.get_the_post_thumbnail($r->ID, array(50,50)).'</a></div>';
}
Or using bitwise:
$i = 0;
foreach ($rel as $r) { // note that I have used curly brackets. I think it is cleaner more standard
$i++;
$classes = array('related-item');
if ($i & 2 == 0) $classes[] = 'right';
echo '<div class="'.implode(' ', $classes).'"><a href='.get_permalink($r->ID).'>'.'<div class=page-related-title>'.$r->post_title.'</div>'.get_the_post_thumbnail($r->ID, array(50,50)).'</a></div>';
}
Or if $rel has a zero based sequenced index:
foreach ($rel as $index => $r) { // note that I have used curly brackets. I think it is cleaner more standard
$classes = array('related-item');
if ($index & 2 == 1) $classes[] = 'right';
echo '<div class="'.implode(' ', $classes).'"><a href='.get_permalink($r->ID).'>'.'<div class=page-related-title>'.$r->post_title.'</div>'.get_the_post_thumbnail($r->ID, array(50,50)).'</a></div>';
}