逐步使用PHP数组循环并检查它是否已达到最大值

I have 200 boxes of which to be named from an array. All names go sequentially and will restart from the first value in the array once previous Box has taken the last name (maximum value?) from the array.

$BoxName = array (Name1, Name2, Name3, Name4, Name5);

The name of first box is always determined by Users through their inputs. The rest of other boxes through coding.

Now i'm using very untrained approach: If Box1 = Name3, given by User's input:

Box1 = Name3 //given by the user

$BoxName = array (Name1, Name2, Name3, Name4, Name5);

$a = 3; //This is given by the User
$b = $a + 1;

if ( $b <= 5 ) {
    $c = $a + 1;
} else {
    $c = 1;
}

$d = $c + 1;

if ( $d <= 5 ) {
    $e = $c + 1;
} else {
  $e = 1;
}
echo $Box1 = $BoxName [3]; // this is given by the user
echo $Box2 = $BoxName [$c];
echo $Box3 = $BoxName [$e];
// ... ... and the list goes on for another 197 boxes.

?>

It obviously looks messy, incorrect and dirty. As a non IT trained dummy, this is the best i can achieve.

Here is where the modulus operator (%) is your friend.

$max_boxes = 200;
$start_box = 3; // box to start with from your example - this is 1-based offset value sent from user
$start_box_offset = $start_box - 1; // box_start position within zero-based array

$box_names = array ('Name1', 'Name2', 'Name3', 'Name4', 'Name5');
$box_name_count = count($box_names);
$box_output = array();

for ($i = 0; $i < $max_boxes; $i++) {
    $modulus = ($i + $start_box_offset) % $box_name_count;   
    $box_output[] = $box_names[$modulus];
}

Note that I have output as array instead of $box1, $box2, etc. as it would be much easier to work with.

$BoxName = array ("Name1", "Name2", "Name3", "Name4", "Name5"); //This is configuration
$BoxCount=200; //This is configuration, as you want 3+197 boxes
$a = 3; //This is given by the User

$boxes=sizeof($BoxName);
for ($i=$1; $i<=$BoxCount; $i++)
  echo "Box $i = ".$BoxName[($a+$i-1) % $boxes];