Código PHP:
<?php
class TableColorManager
{
private $_colors = array();
private $_currentColor = 0;
public function Add($color)
{
if(!is_string($color) && !is_array($color))
{
throw new Exception("\$color parameter must be a string or array");
}
if(is_string($color))
{
$this->AddColor($color);
}
else if(is_array($color))
{
foreach($color as $colorValue)
{
$this->AddColor($colorValue);
}
}
return $this;
}
private function AddColor($color)
{
if(preg_match('/^#[a-f0-9]{6}$/i', $color))
{
array_push($this->_colors, $color);
}
else
{
throw new Exception("Invalid color");
}
}
public function Next()
{
if($this->_currentColor >= count($this->_colors) - 1)
{
$this->_currentColor = 0;
}
else
{
$this->_currentColor++;
}
return $this->_colors[$this->_currentColor];
}
public function Current()
{
return $this->_colors[$this->_currentColor];
}
public function Prev()
{
$returnIndex = ($this->_currentColor - min(2, count($this->_colors)-1));
if($returnIndex < 0)
{
$returnIndex = count($this->_currentColor) + 1;
}
return $this->_colors[$returnIndex];
}
}
$colors = new TableColorManager();
$colors->Add(array("#006699", "#ff00ff"));
$colors->Add("#abc5e2");
for($i = 0; $i < 8; $i++)
{
echo "<table style='width: 200px; height: 100px; border: 1px solid #000; text-align: center; display: inline-block;'>
<tr>
<td style='background-color: " . $colors->Next() . "; height: 10px;'>
Nombre
</td>
</tr>
<tr>
<td>
FOTO
</td>
</tr>
</table> ";
}
?>
Aqui lo tienes...
Saludos