title: Treat an array as circular array when selecting elements - PHP
body: <p>I have an array on which I loop over. I have another array from which I need to select one by one but it needs to go on circle in case it gets to the end of the array. To make it clear here is some code:</p>
  
  <pre><code>$mainArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  $size      = count($mainArray);
  $circular  = array('A', 'B', 'C');
  
  for($i = 0; $i &lt; $size; $i++) {
     echo $mainArray[$i] . ' = ' . $circular[$i] . ', ';
  }
  </code></pre>
  
  <p>Now above code prints this:</p>
  
  <pre><code>1 = A, 2 = B, 3 = C, UNDEFINED INDEX ERROR
  </code></pre>
  
  <p>What I need it to print is this:</p>
  
  <pre><code>1 = A, 2 = B, 3 = C, 4 = A, 5 = B, 6 = C, 7 = A, 8 = B, 9 = C, 10 = A
  </code></pre>
  
  <p>Is there a built in function to PHP that turns an array into circular array? I think I need to use modular operator to achieve this.</p>