Randomly add a class inside a php loop

     

I'm using a php loop on my website.  I'm trying to randomly add a class "current" to a div inside this loop.  I know how to do it using jQuery but I'd liek to use php to achieve this.  here is my loop :


  
    
    
    

I'd like to add the "current" class randomly to the "background_directors" div.


can anybody help me with this ?

  
"
answer1
  
  

You can try something like this :


';   while (have_posts()) :    the_post();   $class = "";   if(!$isAlreadyActive && rand(0 1) == 1 || !$isAlreadyActive && $i == $numberPost):    $class = "current";    $isAlreadyActive = true;   endif;   echo '
';   $i++;   endwhile;   echo '
';   endif;   ?>  
  
  
answer2
  
  

Somethink like this ?


$test = ['class1'