First declare this variable before your while or foreach loop:

<?php $j = ''; ?>

Then paste this code within the class attribute of your element within the loop:

<?php echo (++$j % 2 == 0) ? 'even' : 'odd'; ?>

Example:

<?php
$j = '';
$names = array('Bruce', 'Tony', 'Natasha');
foreach($names as $name):
?>

<p class="<?php echo (++$j % 2 == 0) ? 'even' : 'odd'; ?>"><?php echo $name; ?></p>

<?php endforeach; ?>