Skip to content

Instantly share code, notes, and snippets.

@webrobert
Created January 13, 2023 23:29
Show Gist options
  • Save webrobert/28d3964ed392ca81e0809517e2878f7b to your computer and use it in GitHub Desktop.
Save webrobert/28d3964ed392ca81e0809517e2878f7b to your computer and use it in GitHub Desktop.
reset to zero at length
  $repeat = ['one', 'two', 'three', 'four'];
  $key = 0;
  $x = 0;

  while($x <= 27) {
      echo "{$repeat[$key]}<br/>";
      $key = ++$key % count($repeat); // reset to zero when length is met
      $x++;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment