Ver Mensaje Individual
  #10 (permalink)  
Antiguo 04/05/2013, 18:20
Avatar de bulter
bulter
 
Fecha de Ingreso: enero-2008
Mensajes: 137
Antigüedad: 17 años, 2 meses
Puntos: 20
Respuesta: Alternar Color en DIV

Bueno aqui esta , supongo que ya tiene que ir sin fallos:

Código PHP:
class TableColorManager 

    private 
$_colors = array(); 
    private 
$_currentColor  0

    public function 
AddColor($color
    { 
        if(!
is_string($color)) 
        { 
            throw new 
Exception("\$color parameter must be a string"); 
        } 

        if(
preg_match('/^#[a-f0-9]{6}$/i'$color))  
        { 
            
array_push($this->_colors$color); 
        } 
        else 
        { 
            throw new 
Exception("Invalid color"); 
        } 
     
        return 
$this
    } 

    public function 
getNextColor() 
    { 
        
$returnIndex $this->_currentColor;

        if(
$this->_currentColor >= count($this->_colors) - 1
        { 
            
$this->_currentColor 0
        } 
        else 
        { 
            
$this->_currentColor++; 
        } 

        return 
$this->_colors[$returnIndex]; 
    } 


$colors = new TableColorManager(); 
$colors->AddColor("#ffffff")->AddColor("#ff00ff"); 
$colors->AddColor("#000000"); 
$colors->AddColor("#abc5e2"); 

for(
$i 0$i <= 10$i++) 

    echo 
"Current color: " $colors->getNextColor() . "<br />"
    
// Aqui puedes poner tu codigo y usar $colors->getNextColor() para cojer el color

Saludos.